s/\n//
because it neither scans nor copies the string. If
VARIABLE is omitted, chops $_
. Example:
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).