Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Trimming whitespaces methods

by lodin (Hermit)
on Jun 30, 2008 at 17:02 UTC ( #694777=note: print w/replies, xml ) Need Help??


in reply to Re: Trimming whitespaces methods
in thread Trimming whitespaces methods

In order for the code to be truly equivalent the s modifier should be used on the substitution or a newline may break it.

$_ = " foo\nbar "; s{ ^\s* (\S.*?) \s*$ }{$1}x; print "<$_>"; __END__ < foo bar >
I assume you added the \S in the pattern as an improvement, but it should perhaps be noted that it has the effect of leaving a line of only whitespaces untouched, whereas the other ways don't.

lodin

Replies are listed 'Best First'.
Re^3: Trimming whitespaces methods
by johngg (Canon) on Jun 30, 2008 at 22:33 UTC
    I assume you added the \S in the pattern as an improvement

    No, I think I must have put it in because I wasn't thinking straight :-(

    Well spotted!

    Cheers,

    JohnGG

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2022-01-23 17:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (64 votes). Check out past polls.

    Notices?