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

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

by ikegami (Pope)
on Jan 11, 2006 at 19:22 UTC ( #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
Node Status?
node history
Node Type: note [id://522536]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2020-06-01 06:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?