Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Evaluating code in a regex at runtime: (??{...})

by Athanasius (Chancellor)
on Jan 28, 2013 at 08:44 UTC ( #1015641=note: print w/replies, xml ) Need Help??


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,

Replies are listed 'Best First'.
Re^4: Evaluating code in a regex at runtime: (??{...})
by LanX (Chancellor) on Jan 28, 2013 at 09:09 UTC
    > What we (apparently) canít get is multiple capture groups assigned to different capture groups (whether named or unnamed) from the same dynamic match. Correct?

    apparently yes, like documented:

    DB<131> 'aaa' =~ /(?<outer>(??{'(?<inner>.)' x 1}))/; keys %+ => "outer"

    But of course there are workarounds ... if necessary.

    Cheers Rolf

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015641]
help
Chatterbox?
Discipulus loose the tozzetto party!
[shmem]: .oO( addition of cookies for addiction to cookies )
[Lady_Aleena]: Other than my typos shmem. 8)
[shmem]: otherwise fine
[Discipulus]: tozzetti & vinsanto
[Lady_Aleena]: The whole line is push @line, ref($list_addition ) ? @$list_addition : $list_addition if $list_addition;
[Lady_Aleena]: And I forgot to do the array check, I'm such a doofus today.
[Lady_Aleena]: push @line, ref($list_addition ) eq 'ARRAY' ? @$list_addition : $list_addition if $list_addition; #trying again
[shmem]: Discipulus: yummy. I like those. Didn't have them for some time now, forgot the name. Should go get some...
[shmem]: Lasy_Aleena: correct, although for clarity I'd use an if() block, not a statement modifier

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2017-04-27 11:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (504 votes). Check out past polls.