develooper Front page | perl.perl5.porters | Postings from January 2001

[PATCH pod/perlfunc.pod] removing misuses of chop() and/or replacing with chomp()

Thread Next
From:
Michael G Schwern
Date:
January 31, 2001 14:28
Subject:
[PATCH pod/perlfunc.pod] removing misuses of chop() and/or replacing with chomp()
Message ID:
20010131172820.B5647@blackrider.aocn.com
Well, fuck if I can find a simple example of its use.  I've gotten at
least a dozen suggestions and all of them were either far too
complicated or better and safer done with a regex.  The examples from
Camel 2 are even more misleading.  I don't have Camel 3 handy to see
how they handle it.

I'm going to just strip the chop() examples and misleading suggestions
and leave it there.  I've also replaced misuses of chop() with chomp()
in perlfunc.

I know there are more things of this vein throught the docs and
throughout the library code (Makemaker has quite a few, POSIX...)


--- pod/perlfunc.pod	2001/01/27 21:59:02	1.1
+++ pod/perlfunc.pod	2001/01/31 22:25:43
@@ -300,7 +300,7 @@
 Example:
 
     while (<>) {
-	chop;
+	chomp;
 	next unless -f $_;	# ignore specials
 	#...
     }
@@ -629,23 +629,11 @@
 =item chop
 
 Chops off the last character of a string and returns the character
-chopped.  It's used primarily to remove the newline from the end of an
-input record, but is much more efficient than C<s/\n//> because it neither
+chopped.  It is much more efficient than C<s/.$//s> because it neither
 scans nor copies the string.  If VARIABLE is omitted, chops C<$_>.
-Example:
-
-    while (<>) {
-	chop;	# avoid \n on last field
-	@array = split(/:/);
-	#...
-    }
-
 If VARIABLE is a hash, it chops the hash's values, but not its keys.
 
-You can actually chop anything that's an lvalue, including an assignment:
-
-    chop($cwd = `pwd`);
-    chop($answer = <STDIN>);
+You can actually chop anything that's an lvalue, including an assignment.
 
 If you chop a list, each element is chopped.  Only the value of the
 last C<chop> is returned.
@@ -4435,13 +4423,12 @@
 
     open(PASSWD, '/etc/passwd');
     while (<PASSWD>) {
-	($login, $passwd, $uid, $gid,
+        chomp;
+        ($login, $passwd, $uid, $gid,
          $gcos, $home, $shell) = split(/:/);
 	#...
     }
 
-(Note that $shell above will still have a newline on it.  See L</chop>,
-L</chomp>, and L</join>.)
 
 =item sprintf FORMAT, LIST
 


-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Our business in life is not to succeed but to continue to fail in high spirits.
		-- Robert Louis Stevenson

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About