Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Recursively executed function in regex RHS, AKA "wait, why does this work?"

by jellisii2 (Hermit)
on Oct 21, 2014 at 11:52 UTC ( [id://1104562]=note: print w/replies, xml ) Need Help??


in reply to Recursively executed function in regex RHS, AKA "wait, why does this work?"

g in your regex means that it'll happen globally, so every instance will get processed, so line 7 actually gets fired multiple times. It APPEARS that since the line is getting modified after the current evaluation, that gets caught and processed. Testing seems to confirm this, as when you replace the IDs with 5 it works as expected. As to an actual reason as to WHY this is, I'd be interested in knowing myself. I assume that backtracking has something to do with this. perlre's section on backtracking may explain it better.

See Choroba's response. I missed the quite obvious fact that it was calling itself.
  • Comment on Re: Recursively executed function in regex RHS, AKA "wait, why does this work?"
  • Download Code

Replies are listed 'Best First'.
Re^2: Recursively executed function in regex RHS, AKA "wait, why does this work?"
by Eily (Monsignor) on Oct 21, 2014 at 13:18 UTC

    You're still right about /g being necessary for this to work. The recursion processes the descendants and the /g modifier makes sure all siblings are processed. There are actually two loop-like constructs in this code. s/REG/REPL/g does not however process the replaced text, or something like s/(.)/$1$1/g; would be an infinite loop.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found