- The chop function removes the last character from
the supplied scalar string variable.
- Example:
$TheString = "Hello World!";
chop($TheString); # Now $TheString contains "Hello World" without the "!"
- The chomp function removes the last character(s)
from the string if they correspond to your systems newline
character.
- Example:
$TheString = "Hello World\n";
$TheString2 = "Hello World";
chomp ($TheString);
chomp ($TheString2);
# $TheString and $TheString2 equal "Hello World" with no "\n"
- Both chop and chomp return the characters they deleted.
- Example:
$Name = "Reepicheep";
$TheChar = chop $Name; # $TheChar = "p", $Name = "Reepichee"