Products
Services
Contact Us

Scripts: Perl :: String Functions :: Library Article #1

Developer's Section

Trim a String in Perl
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (2054)
Favorites:

Code and explanation of a Trim function for the Perl Programming language.

There is a simple function you can build to trim strings in your Perl programs.
The function uses two regular expressions to trim a string from the left side of the string as well as one for the right side.

 Code Snippet 1

#!/usr/bin/perl -w

# Perl trim function 

sub trimStr($){

my $string = shift;
           # the first regular expression removes space
           # from the left side
$string =~ s/^\s+//;
           # the second regular expression removes space
           # from the right side
$string =~ s/\s+$//;

return $string;

}

exit 0;


See other Scripts in String Functions

Submit Your Scripts:

If you would like to have your Perl scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]