Chop: Removing the last character, regardless of what it is
#!usr/bin/perl
use warnings;
use strict;
print "Input something and we'll print it: ";
my $string = <STDIN>;
print "\nOur input ( $string ) contains a newline. Remove it:\n";
chop( $string );
print "\nThis is more like it: '$string' without the newline.\n";
my $character = chop( $string );
print "\nWe removed $character; now it is '$string.'\n";
Related examples in the same category