Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: remove both leading and trailing spaces

by Ordinary_User (Beadle)
on Sep 26, 2003 at 21:09 UTC ( [id://294543]=note: print w/replies, xml ) Need Help??


in reply to remove both leading and trailing spaces

Given that $val holds the text as you describe in your code, I'd be using the following:

$val =~ s/ //g;

This will remove all "blanks" from the string and replace them with "nothing", thus removing all blanks from the string, in one swift stroke.

The "g" is important! Without it, it will only remove one blank from the string.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2024-04-16 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found