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!


In reply to Re: CR+LF by jsprat
in thread CR+LF by Gorio3721

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.