chomp() will remove the end of line character(s).
On Windows these will be 0xOA, 0x0D.
On Unix this just 0x0D.
Perl is permissive about what it receives for a text line. chomp() will remove the end-of-line character(s) - might be 1 or might be 2 bytes.
When Perl writes a line: print "something\n"; , that \n may be one or two characters depending upon the OS and the context (network communication uses 0xOA, 0x0D - no matter what the OS) - but Perl knows about this and does the "right thing".
If I transfer a file from Windows to Unix, sometimes I need to do something like this to "convert" the file:
while (<STDIN>)
{
chomp; #remove line endings
print "$_\n"; #write this OS's line ending
}
"chomp()" is your friend as opposed to "chop()". chop() is seldom used.
The 'C' functions that read lines do the "chomp" automatically for you.
In Perl you have to do this yourself.
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.