Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: what is the function should I need to use for trim white spaces ?

by ikegami (Patriarch)
on Jan 11, 2006 at 19:22 UTC ( [id://522536]=note: print w/replies, xml ) Need Help??


in reply to what is the function should I need to use for trim white spaces ?

Your code is missing an s, so it won't do what you want.

That aside, you could use the following rather obfuscated code:

s/^\s+//g, s/\s+$//g for $value;
But it's probably better just to make a function:
sub trim { local $_ = @_ ? $_[0] : $_; s/^\s+//g; s/\s+$//g; $_ } $trimmed = trim($untrimmed); $trimmed = trim; # Trims $_ by default. @trimmed = map trim, @untrimmed; # Trim a whole list. (readable) push(@trimmed, trim) for @untrimmed; # Trim a whole list. (efficient)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-25 10:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found