The chop keyword[edit | edit source]
The chop function chops off the last character of a string and returns it. It is much more efficient than s/.$//s, as it neither scans nor copies the string. Without VARIABLE, it chops $_. If VARIABLE is a hash, it chops the hash's values, not its keys, and resets the each iterator in the process.
If a list is chopped, each element is chopped off, but only the value of the last chop is returned. Note that chop returns the last character. To return all but the last character, substr($string, 0, -1) should be used.
Syntax[edit | edit source]
chop VARIABLE chop(LIST) chop
Examples[edit | edit source]