Home >> perlfunctions >>Perl function: chompSyntax:chomp VARIABLE chomp (LIST) chompIt's a safer version of chop. Removes any newline character from the end of the string. It actually removes any character that matches the current value of $/ where $/ means a newline.
Chomping a string: Chomping a hash: When a hash is chomped, newlines from all the values of the hash are removed. Example: Chomping an array: Chomping an array removes newline from the end of all the elements of the array. Example: #!/usr/bin/perl
use strict;
use warnings;
my @array = ("apple", "orange\n", "grape\n");
print "Array before chomping:\n";
print "@array\n";
chomp(@array);
print "Array after chomping:\n";
print "@array\n";
Output:
Array before chomping: apple orange grape Array after chomping: apple orange grape Perl functions
|
List of all perl functions Perl function : split Perl function: abs Perl function: chop Perl function: chr Perl function: crypt Perl function: eval Perl function: hex Perl function: lc Perl function: lcfirst Perl function: length Perl function: oct Perl function: ord Perl function: shift
|