http://qs321.pair.com?node_id=694777


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