Monday, July 18, 2011

Perl trim function

# Function Name : trim
# Input : String with or without spaces around it
# Output : String without spaces around it
# Description : This function would remove whitespace from the start and end of the string
#
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}

No comments:

Post a Comment