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 davido (Cardinal)
on Jan 11, 2006 at 19:17 UTC ( [id://522534]=note: print w/replies, xml ) Need Help??


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

There's not a built-in. The regexp approach is fine. If you want it to be a sub, just put it in a sub definition:

sub trim_white { my $string = shift; $string =~ s/^\s+//g; $string =~ s/\s+$//g; return $string; } # Usage example: my $trimmed = trim_white( $untrimmed );

Update: For completeness's sake, it might be worth noting that on CPAN you can find String::Util, which includes a function called trim() that does exactly what you're talking about. ...it's been done. ;)


Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-26 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found