Trim strings

12 Jun 2007

In Perl, you want to remove white-space at beginning and end of strings.

sub trim {
  my $str = shift;
  $str =~ s/^\s+//;
  $str =~ s/\s+$//; 
  return $str;
}