Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Trimming whitespaces methods

by lodin (Hermit)
on Jun 30, 2008 at 17:02 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-19 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found