No, that's completely wrong. chomp removes what's in $/ from the end of its arguments. $/ is equal to \n (by default) in Windows, so chomp only removes \n (by default) on Windows too.

die("\\n ne LF\n") if "abc\n" ne "abc\x0A"; print("\\n eq LF\n"); $s = "abc"; $l1 = length($s); chomp($s); $l2 = length($s); if ($l1 - $l2 == 0) { print("abc unchanged\n"); } else { print("???\n"); } $s = "abc\n"; $l1 = length($s); chomp($s); $l2 = length($s); if ($l1 - $l2 == 1) { print("\\n removed from abc\\n\n"); } elsif ($l1 - $l2 == 0) { print("abc\\n unchanged\n"); } else { print("???\n"); } $s = "abc\r\n"; $l1 = length($s); chomp($s); $l2 = length($s); if ($l1 - $l2 == 2) { print("\\r\\n removed from abc\\r\\n\n"); } elsif ($l1 - $l2 == 1) { print("\\n removed from abc\\r\\n (\\r kept)\n"); } elsif ($l1 - $l2 == 0) { print("abc\\r\\n unchanged\n"); } else { print("???\n"); } __END__ ActivePerl v5.8.0 on WinXP -------------------------- \n eq LF abc unchanged \n removed from abc\n \n removed from abc\r\n (\r kept)

Perl translates CR+LF to LF for you when you read from a file in Windows (unless you use binmode on that handle). Similarly, Perl translates LF to CR+LF when writting to a file handle in Windows (unless you use binmode on that handle).

The reason to use chomp is to handle the case where a line without the line terminator is read in. chop would fail to perform as desired there, but chomp wouldn't. That has nothing to do with CR+LF vs LF.

Update: Added underlined text to clarify my intended message, at GrandFather's recommendation.


In reply to Re^2: Problem with <STDIN> by ikegami
in thread Problem with <STDIN> by sivaramanm

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.