in reply to Re^2: Trim blanks from the beginning and end of a multi-line string
in thread Trim blanks from the beginning and end of a multi-line string
s{ \A \s+ | \s+ \z }{}xmsg;I don't think this deserves any price for clearity.
You're using /m and /s while you aren't using any construct for which this is relevant. This just leads to more people like the OP who will think that using /m and /s is a good idea, without understanding their meaning. And then use it at the wrong time. Furthermore, I don't see the point of /g. It's just an artificial way of putting two constructs into one. The /x j u s t m a k e s i t l i k e y o u r r e g e x p s u f f e r s f r o m b a d k e r n i n g .
I'd write it as:
if only because it's idiomatic.$str =~ s/^\n+//; $str =~ s/\n+$//;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Trim blanks from the beginning and end of a multi-line string
by AnomalousMonk (Archbishop) on Jan 29, 2012 at 21:36 UTC |