Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by dave_the_m (Parson)
on Jan 28, 2013 at 01:12 UTC ( #1015606=note: print w/ replies, xml ) Need Help??


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

When a pattern is compiled, all the captures are allocated fixed indices: so for example when the following pattern is compiled, the indices shown are assigned.

/(....)...(...)...(??{foo()})....(...)/ ^ ^ ^ 1 2 3
In particular, the last capture is index number 3.

Each time the pattern is run, foo() might return a string or qr// which has a different number of captures; and which might recursively also include /(??{...})/ and further nested captures. This would make it nearly impossible to guess how to refer to the final capture in the outer pattern, unless we just always call it $3.

Dave.


Comment on Re: Evaluating code in a regex at runtime: (??{...})
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015606]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2015-07-29 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (262 votes), past polls