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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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



Nov 29, 2001, 7:35 AM

Post #1 of 3 (3054 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


Nov 29, 2001, 8:59 AM

Post #2 of 3 (3053 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



Dec 1, 2001, 5:55 AM

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


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