Perl chop() and chomp()Both the functions are quite similar. Both of them remove one character from the end of the given string. Perl chop()The Perl chop() function removes last character from a string regardless of what that character is. It returns the chopped character from the string. Syntax: Perl chop() exampleOutput: AEIO U Look at the output, at first, variable $a is printed after chopping. Then variable $b is printed which returns the chopped character from the string. Perl chomp()The chomp() function removes any new line character from the end of the string. It returns number of characters removed from the string. Syntax: Perl chomp() exampleOutput: AEIOU 0 AEIOU 1 Look at the output, at first, variable $a does not contain any new lone character. Then it is passed in variable $b and printed. It returns 0 as no character is removed. Now, variable $a contains a new line character. When it is passed in $b, it returns 1 as it removes one new line character. Next TopicPerl Directories |