liupang has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a simple script to upload some graphic:
open OUTFILE, ">${TempPath}$ImageFileName"; while (<$image_file>) { print OUTFILE $_; } close OUTFILE;
this works fine for me on UNIX , but when I migrate my codes to a NT box, something weird happened. The image file isn't right. I checked the hex code for the saved file and find there is several additional bytes in the new file. So what's the take??!!

Thanks in advance for help!

Edit: chipmunk 2001-03-20

Replies are listed 'Best First'.
(jcwren) Re: Copying under Windows?
by jcwren (Prior) on Mar 21, 2001 at 04:33 UTC

    0x0a (newline under linux) is getting transliterated to 0x0d/0x0a (carriage return/linefeed) under DOS/Windows.

    Try binmode (OUTFILE); after the open.

    It has to do with the way various operating systems interpet the character used to indicate an end of line. *nix's have always used a single character, 0x0a (represented by '\n', or the ASCII 'LF' name) to indicate an end of line. DOS/Windows uses a carriage return (symbolized by '\r', or the ASCII 'CR' name), followed by a linefeed (symbolized by '\n', ASCII 'LF'). Macs store it yet another way (I think it's 0x0a then 0x0d, but I'm not versed in Macs).

    For more details, see the 'perldoc -f binmode' page.

    --Chris

    e-mail jcwren

      binmode($image_file) as well or you won't be able to read past any CTRL-Zs in the input file.

              - tye (but my friends call me "Tye")
      Thx! That was fast... I am reading the documents for binmode right now...