When I run this code

open (FH,'>',"linefeed.txt"); # binmode FH; # I have added this line print FH "This is a line\r\n" __END__ This is a line^M (viewed under gvim on win XP SP 2)
Uncomment the binmode FH and re-run

Output

This is a line (NOTE: no ^M)<p>

perldoc -f binmode On some systems (in general, DOS and Windows-based systems) binmode() +is necessary when you're not working with a text file. For the sake +of portability it is a good idea to always use it when appropriate, a +nd to never use it when it isn't appropriate.

update: Guess I am joining this thread a bit late now!

As others have mentioned CRLF translation is done automatically by Perl. So you are better off using \n in windows and Perl will take care of the rest.

OK what's the scoop with binmode and why did the problem go away?

The reason is that binmode() does not translate \n => CRLF and rather does \n=>LF. Since you are doing \r\n it becomes => CR(i.e. \r)LF(i.e.\n) in binmode!

-SK


In reply to Re: CRLF and Windows XP SP2 by sk
in thread CRLF and Windows XP SP2 by slloyd

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.