| Refresh | Home EGTry.com

perl - chop -


chop off the last character

perl code

$word="USA";
$lastChar=chop($word);
print "lastChar=$lastChar, word=$word\n";



Output

lastChar=A, word=US


chop off last characters of every array element

perl code

@list=("USA", "CHINA", "JAPAN");
$lastChar=chop(@list);
print "lastChar=$lastChar, list=", join(",", @list), "\n";


Output

lastChar=N, list=US,CHIN,JAPA