Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Trimming whitespaces methods

by Anonymous Monk
on Jun 30, 2008 at 14:18 UTC ( [id://694744]=note: print w/replies, xml ) Need Help??


in reply to Trimming whitespaces methods

If you do not want to use the existing (and strongly recommended) utilities noted in other posts, I would use the expression

   s{ \A \s+ | \s+ \z }{}xmsg for @array;

Note that $_ is implicitly bound to the regex and so there is no need to use the expression $_ =~ s///.
Furthermore, the use of \s* in the expression you originally posted means that a substitution will be done in every string, since every string has zero or more whitespace at its beginning and end.

To trim the values of a hash, use an expression like

   s{ \A \s+ | \s+ \z }{}xmsg for values %hash;

It is not clear to me what you mean by trimming the 'keys' of a hash: altering a hash key (which is a string) creates a different key.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://694744]
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-24 02:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found