diff options
author | Xavier Noria <fxn@hashref.com> | 2006-05-02 14:08:34 +0200 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2006-05-02 10:11:10 +0000 |
commit | 31bb23b166683ca82ab1aa9af0910e80eb18a1d3 (patch) | |
tree | bb4c5bd783d6cead89e6ea343e22ca4241a078cb /pod/perlport.pod | |
parent | 80e18237757da0670ddbfa6973109e70dbad24f3 (diff) | |
download | perl-31bb23b166683ca82ab1aa9af0910e80eb18a1d3.tar.gz |
[DOC PATCH] chop warning in perlport
Message-Id: <E06C0594-CAF6-4822-8EB4-8E06EAD4A889@hashref.com>
p4raw-id: //depot/perl@28054
Diffstat (limited to 'pod/perlport.pod')
-rw-r--r-- | pod/perlport.pod | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/pod/perlport.pod b/pod/perlport.pod index de753e7844..b639c47763 100644 --- a/pod/perlport.pod +++ b/pod/perlport.pod @@ -94,21 +94,9 @@ from) C<\015\012>, depending on whether you're reading or writing. Unix does the same thing on ttys in canonical mode. C<\015\012> is commonly referred to as CRLF. -A common cause of unportable programs is the misuse of chop() to trim -newlines: - - # XXX UNPORTABLE! - while(<FILE>) { - chop; - @array = split(/:/); - #... - } - -You can get away with this on Unix and Mac OS (they have a single -character end-of-line), but the same program will break under DOSish -perls because you're only chop()ing half the end-of-line. Instead, -chomp() should be used to trim newlines. The L<Dunce::Files> module -can help audit your code for misuses of chop(). +To trim trailing newlines from text lines use chomp(). With default +settings that function looks for a trailing C<\n> character and thus +trims in a portable way. When dealing with binary files (or text files in binary mode) be sure to explicitly set $/ to the appropriate value for your file format |