http://www.perlmonks.org?node_id=267053


in reply to CR+LF

Here's a long answer, use one of the following:
  1. Explicitly print your line ending - use chr(13) or "\x0d" or "\015" or "\cM" instead of "\n"
  2. Convert the file from dos2unix using your favorite utility.
  3. In memory, perl sees no "\r\n" - only on output does it get translated. "binmode STDOUT; #any filehandle, not just STDOUT" prevents this translation.
  4. Change the output record separator , and print no explicit line ending, ie $\ = chr(13); print "This is my line"; #no line ending
  5. If the file is transferred by ftp, be sure it is ftp'ed in ascii mode

Short answer - use method 1 if the file is only to be used on *nix platforms. Use 2 if you need the file on both platforms.

HTH...

BTW, more than once I've wished for a command line switch (or configuration variable) to specify the value of the newline character.

Update: I always get cr & lf backwards - is it 10 and 13 or 13 and 10 :(

And thank you Tye for the pointer to your Line Feeds node - printing \0x0A puts a \r\n into the file!