FAQ

On 2013-11-15 11:55, Ed Avis wrote:
Yves Orton wrote:
@CAPTURE= /(.)(.)(.)/ or die;
Why would having a magic var for this be better?
I mentioned one reason in the original report: in s/// you don't have access to this.
You have to do s/$re/foo($1,$2,$3,$4,$5...)/
    @CAPTURE = m/$re/ and s//foo(@CAPTURE)/e

But what if the g-modifier is used, AoA?

perl -Mstrict -MData::Dumper -wle '
    $_ = q{a bc def};
    my $re = q{(\w?)(\w?)(\w?)};
    print "[@-]\t[@+]\t[$1,$2,$3]" while /$re/g;
'
[0 0 1 1] [1 1 1 1] [a,,]
[1 1 1 1] [1 1 1 1] [,,]
[2 2 3 4] [4 3 4 4] [b,c,]
[4 4 4 4] [4 4 4 4] [,,]
[5 5 6 7] [8 6 7 8] [d,e,f]
[8 8 8 8] [8 8 8 8] [,,]

--
Ruud

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2021 Grokbase