in reply to Re: /g option not making s// find all matches
in thread /g option not making s// find all matches
... keeps the whole thing inside a single s/// operator.
The only thing I would say about this is that you're firing up the eval-uator behind the scenes, so
s/^ ~ .* /@{[ ${^MATCH} =~ tr#_#+#r ]}/xp;
is (I think; haven't tested it) exactly equivalent to
s/^ ~ .* / ${^MATCH} =~ tr#_#+#r /xpe;
That's an awful lot of moving parts for what seems a fairly simple match and transformation. Getting back to Eily's first solution and in particular to tybalt89's solution, I don't see a problem with something like (also untested):
Simple, clear, one-step fixup, do whatever you want with the line thereafter.while (<FILEHANDLE>) { tr/_/+/ if m{ \A ~ }xms; do_something_with_fixed_up_line($_); }
Oh, and BTW: Please don't use # as a delimiter for regex expressions; I know we're talking TimToady here, but there's no need for perversity!
Give a man a fish: <%-{-{-{-<
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: /g option not making s// find all matches
by raygun (Scribe) on Jun 01, 2018 at 04:11 UTC |