CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Problem with N in pack()

 



yapp
User

Nov 29, 2001, 7:35 AM

Post #1 of 3 (2160 views)
Problem with N in pack() Can't Post

Hello there.

Some time ago I posted something about binary files.

Still I have a problem with making it compatible.
I have read something about using 'N' or 'n' in the string for pack() and unpack(). I thought that using those codes for saving numbers would make the file compatible, so I can transfer it to other locations.

However, If I FTP the file, and let my script use it at my local testserver (win2000 / iis5) All numbers are different. (something with little/big endians) That webserver used some linux version (off course Wink).

How can I solve this / prevent it from happening?

Yet an Other Perl Programmer

_________________________________
Find out more about programming
http://www.cool-programming.f2s.com


mhx
Enthusiast

Nov 29, 2001, 8:59 AM

Post #2 of 3 (2159 views)
Re: Problem with N in pack() [In reply to] Can't Post

If the server is running Linux, it most likely has the same byteorder (little endian). It's not OS specific, it only depends upon the used hardware, and Linux is most often used on Intel (little endian) machines.

I believe it has to do with the way you open and transfer files. When dealing with binary files (such as created by pack) be sure to always use binmode before reading/writing the file and be sure to always transfer (ftp) the file in binary mode. The big difference between Windows and Unix (including Linux) is the newline sequence. And if you print a packed string that contains a \n character in non-binary mode under Windows, it will be converted to a \r\n sequence, which is of course wrong for a binary file. Opening that file under Windows reverses that transform, so you end up with the correct data under Windows. But a Linux system will read the raw data, mixing up your binary packed string.

I hope this was your problem. Wink

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



yapp
User

Dec 1, 2001, 5:55 AM

Post #3 of 3 (2152 views)
Re: Problem with N in pack() [In reply to] Can't Post

Thanks.

I solved the problem...

I did everything OK, tested everything locally in win2k iis 5...

I downloaded the files, but as ASCII. (autoselect using file extensions sux). I really need a better FTP program Wink

Yet an Other Perl Programmer

_________________________________
X-Forum - Members and testers wanted Wink

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives