Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by jZed (Prior)
on Jan 11, 2006 at 19:17 UTC ( #522535=note: print w/replies, xml ) Need Help??


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

> Hi Gr8 People

Please don't use those kinds of abbreviations. There are people speaking many languages who come here and there's no point in making things harder for them to understand.

> Is there any other built in function available to do the stuff.

No, the way you showed is the best way (except you don't need the "g" since you already get all the spaces with "+").

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

Replies are listed 'Best First'.
Re^2: what is the function should I need to use for trim white spaces ?
by davido (Cardinal) on Jan 11, 2006 at 19:24 UTC

    I thought about this too. You're correct that the /g modifier is kind of pointless by itself, but combined with the /m modifier, you get improved functionality (for some definitions of 'improved'):

    use strict; use warnings; my $string = " now is the \ntime for all \n good men to co +me \n to the aid\n"; $string =~ s/^\s+//mg; $string =~ s/\s+$//mg; print $string, "\n";

    Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2020-06-05 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (35 votes). Check out past polls.

    Notices?