Yes, "The behavior of chomp is independent of OS", True. Perl chomp will work fine across platforms.
The "\n" in Perl generically means the "end of line" character(s).
On Windows, this means "carriage return, line feed". On Unix a
single "line feed" is used, implying the "carriage return".
I have a setup that allows me to use my local Windows Text editor to
edit remote Unix files. When I send the file back to Unix, it can
have mixed line endings (sometimes just a line feed and sometimes
a carriage return and a line feed). Perl doesn't care about this
and it not an issue. Some Unix utilites are not as "forgiving".
The easy way to "normalize" the line endings to the current platform:
while (<>)
{
chomp; #removes line endings of both varieties
print "$_\n"; #prints with this platform's line endings.
}
My main point was that chomp() is not needed because in this case, the line ending character(s) count as white space.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.