Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Just another Perl shrine
 
PerlMonks  

Re: Strip leading and trailing blanks

by snax (Hermit)
on Jul 30, 2003 at 12:18 UTC ( [id://279237]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Strip leading and trailing blanks

TIMTOWTDI :)

I've always been fond of this, which also compresses "extra" spaces in the middle to a single space:

$name = join ' ', split ' ', $name;
It's not all that much slower than the others, and if you want to compress the internal whitespace it's hard to beat. Lots of my proggies have a little sub:
sub wsp { $_ = shift; join ' ', split; }
which takes advantage (in terseness, not speed) of the magic of $_ and split's default behavior.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://279237]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.