note 37057 deleted from function.chop by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 13:08:42 +0000 |
| Subject: | note 37057 deleted from function.chop by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155669@lists.php.net to get a copy of this message | ||
Note Submitter: php at newmediaone dot com
----
The above notes are confusing 2 different Perl fuctions, chop and chomp.
In Perl, chop removes and returns the last charecter of a string. This function was often used in
Perl <= version 4 to remove newlines, and in some cases, you'd think you were choping a new
line, but if the last charecter wan't a newline, chop would still remove it.
As of Perl 5, chomp (note the "m") was introducted. Chomp removes the last character(s)
of a string only if those chatecters are new lines, and it returns the number of characters deleted.
(If the string ends in multiple newlines, they will all be choped off, and if the last charecter is
not a new line, nothing will be choped off.)
So, I don't think either of the above examples quite duplicate Perl's chomp, but they are
both very helpful.