Perl chop chomp

sub spacer

{ print “<br />”; }

my $text = “This is one heck of a story”;

# remove the last character

print chop($text); spacer(); # returns y

print $text; spacer(); # we can see that it also DID alter the variable

# remove newlines from the end of a string only

$text = $text . “\n\n”;

print $text; spacer();

print chomp($text); spacer(); # again, returns # of items “chomp”ed 🙂

print $text; spacer();

Leave a Reply

You must be logged in to post a comment.