chop takes off the last character of the string oblivious to what it is.
chomp takes off $/ ("\n" by default) if it exists as the last character, also known as the input record seperater
See
perldoc -f chomp, vs
perldoc -f chop for more information.
chop returns what was taken off,
chomp returns how many was taken off, (how many elements it effected).
chomp is most often used when reading from <STDIN>.
perl -e'$_="foo\n*"; chop; chomp; print;' ## Removes the *, then removes the terminating $/ (\n), prints foo
perl -e'$_="foo\n*"; chomp; chop; print;' ## There is no terminating $/ (\n) chomp returns 0, chop removes *, prints foo\n
Evan Carroll
www.EvanCarroll.com