The underlying question revolves around removing leading and trailing whitespace from strings, and has been answered in several threads in some form or another with the following regex substitution (or its equivalent):
s{^\s+|\s+$}{}g foreach @array;
chomp
ing the array will remove only trailing input record separators ("\n"
by default). It is not designed to remove trailing whitespaces.
From perldoc -f chomp
:
It's often used to remove the newline from the end of an input record when you're worried that the final record may be missing its newline. When in paragraph mode ($/ = ""
), it removes all trailing newlines from the string.
...
If you chomp a list, each element is chomped, and the total number of characters removed is returned.