chomp removes the contents of
$/ from the end of the string (if present), and
$/ defaults
"\x0A" on all systems.
Perl on Windows defaults to adding the :crlf PerlIO layer to handles. It causes CRLF to become LF on read, and the reverse on write. As such, when reading a Windows file on Windows, everything looks the same as it would on unix. If you read a line from a file containing "65 66 67 0D 0A", you'll get string "65 66 67 0A". chomp will happily remove the trailing line feed.
When you'll have problems is when you read a Windows file on unix. The :crlf layer won't be present (by default), so the CR will appear in the read data along with the LF. chomp will happily remove (only) the trailing line feed, leaving the carriage return behind.
Solution:
while (<$fh>) {
s/\s+\z//; # More flexible than chomp.
...
}
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.