In order for the code to be truly equivalent the s modifier should be used on the substitution or a newline may break it.
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.$_ = " foo\nbar "; s{ ^\s* (\S.*?) \s*$ }{$1}x; print "<$_>"; __END__ < foo bar >
lodin
In reply to Re^2: Trimming whitespaces methods
by lodin
in thread Trimming whitespaces methods
by harishnuti
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |