|
|
| Just another Perl shrine | |
| PerlMonks |
perlfunc:chopby gods |
| on Aug 24, 1999 at 22:43 UTC ( #303=perlfunc: print w/ replies, xml ) | Need Help?? |
chopSee the current Perl documentation for chop. Here is our local, out-dated (pre-5.6) version: ![]() chop - remove the last character from a string
![]() chop VARIABLE chop LIST 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
while (<>) {
chop; # avoid \n on last field
@array = split(/:/);
#...
}
You can actually chop anything that's an lvalue, including an assignment:
chop($cwd = `pwd`);
chop($answer = <STDIN>);
If you chop a list, each element is chopped. Only the value of the last chop() is returned. Note that chop() returns the last character. To return all but the last character, use substr($string, 0, -1). |
|