http://www.perlmonks.org?node_id=1015641


in reply to Re^2: Evaluating code in a regex at runtime: (??{...})
in thread Evaluating code in a regex at runtime: (??{...})

Yes, you’re right. So in dave_the_m’s example, all we need to do is add another set of parentheses:

/(....)...(...)...((??{foo()}))....(...)/ ^ ^ ^ ^ 1 2 3 4

and the dynamically generated capture group is assigned to $3. For example:

use Modern::Perl; my $str = 'abcd$$$$$ef'; my @caps = $str =~ /(a)b(c)d((??{'(.)' x 5}))e(f)/; say join(', ', @caps);

Output:

18:33 >perl 504_SoPW.pl a, c, $$$$$, f 18:38 >

What we (apparently) can’t get is multiple capture groups matches assigned to different capture groups (whether named or unnamed) from the same dynamic match. Correct?

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,