Created
October 1, 2011 09:31
-
-
Save managai/1255802 to your computer and use it in GitHub Desktop.
(perl) trim function to strip whitespace from a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Perl trim function to remove whitespace from the start and end of the string | |
sub trim($) | |
{ | |
my $string = shift; | |
$string =~ s/^\s+//; | |
$string =~ s/\s+$//; | |
return $string; | |
} | |
# Left trim function to remove leading whitespace | |
sub ltrim($) | |
{ | |
my $string = shift; | |
$string =~ s/^\s+//; | |
return $string; | |
} | |
# Right trim function to remove trailing whitespace | |
sub rtrim($) | |
{ | |
my $string = shift; | |
$string =~ s/\s+$//; | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment