diff options
author | Michael G. Schwern <schwern@pobox.com> | 2001-02-03 17:46:38 -0500 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-02-04 17:55:24 +0000 |
commit | 5b3eff12f7c4ea0bd1324f2fe0a16edec8764c93 (patch) | |
tree | 7de82155c4854f5aa16ba942e44d9d0f8d021539 /pod/perlport.pod | |
parent | bccbfa77316f269e35ea29247d7506d2c3ba7e11 (diff) | |
download | perl-5b3eff12f7c4ea0bd1324f2fe0a16edec8764c93.tar.gz |
Re: [PATCH lots of pod/] s/chop/chomp/g
Message-Id: <20010203224638.E10493@blackrider.aocn.com>
p4raw-id: //depot/perl@8689
Diffstat (limited to 'pod/perlport.pod')
-rw-r--r-- | pod/perlport.pod | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/pod/perlport.pod b/pod/perlport.pod index 1078e58bf3..08a1704baf 100644 --- a/pod/perlport.pod +++ b/pod/perlport.pod @@ -94,6 +94,26 @@ 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 MacOS (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 Dunce::Files module can +help audit your code for misuses of chop(). + +When dealing with binary files (or text files in binary mode) be sure +to explicitly set $/ to the appropriate value for your file format +before using chomp(). + Because of the "text" mode translation, DOSish perls have limitations in using C<seek> and C<tell> on a file accessed in "text" mode. Stick to C<seek>-ing to locations you got from C<tell> (and no |