[sf-perl] amusing bug
Joe Brenner
doom at kzsu.stanford.edu
Tue May 4 13:02:44 PDT 2010
David Alban wrote:
> it's so easy to miss the error in:
>
> $line =~ s{ s+ \z }{}xms;
>
> when you expect to see:
>
> $line =~ s{ \s+ \z }{}xms;
>
> i wondered why one of the lines was having its last character stripped
> but the others were ok.
The one I like is
$line =~ s{ ^ \s+ (.*?) \s+ $ }{ $1 }x;
It always takes me awhile to figure out why the leading and
trailing spaces aren't all going away.
(I need a \X modifier that makes spaces insignificant in the
replace string as well as in the find pattern.)
More information about the SanFrancisco-pm
mailing list