in reply to Re: Mapping list to hash is dropping list items
in thread Mapping list to hash is dropping list items
sub myTrim { my $str = shift; #shift faster than @_ for one paramater $str =~ s/^\s*//; #no space at front $str =~ s/\s*$//; #no space at rear return $str; }
Trimming leading and trailing whitespace from a string is a FAQ. Like you, I think it's simplest and clearest to do it in two simple statements. To nickpick your solution, it's better to replace * with + like so:
$str =~ s/^\s+//; # no whitespace at front $str =~ s/\s+$//; # no whitespace at rear
See also:
|
---|