Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Mapping list to hash is dropping list items (trim whitespace)

by eyepopslikeamosquito (Archbishop)
on Mar 13, 2022 at 12:06 UTC ( [id://11142069]=note: print w/replies, xml ) Need Help??


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:

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11142069]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found