We can use the chop()
method to remove the last character of a string in Perl. This method removes the last character present in a string. It returns the character that is removed from the string, as the return value.
chop(str)
str
: This is the string whose last character we want to remove.
The value returned is the last character that is removed from the string.
# create strings$string1 = "Educative is the best";$string2 = "Perl language is interesting";$string3 = "Perl developer";# remove last strings$r1 = chop($string1);$r2 = chop($string2);$r3 = chop($string3);# print removed charactersprint "$r1\n";print "$r2\n";print "$r3\n";# print stringsprint "$string1\n";print "$string2\n";print "$string3\n";
chop()
method on the strings we created, and then we store the results in the variables $r1
, $r2
, and $r3
.chop()
method, to the console.