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

Re^3: substitute with recursive regexps?

by Anonymous Monk
on Sep 04, 2011 at 21:14 UTC ( #924122=note: print w/ replies, xml ) Need Help??

in reply to Re^2: substitute with recursive regexps?
in thread substitute with recursive regexps?

Yes, Regexp::Grammars basically just automates the same technique as demerphq's example uses: injection of a distributed stack-based tree-constructor via embedded code blocks.

But you really want that automation if the regex gets much more complex than the above example. Apart from the obvious maintainabilty issues of sprinkling dozens of (?{...}) blocks through your regex, there's a much more fundamental problem: if the regex can ever backtrack a repetition, that will almost certainly screw up the synchronization between the stack and the parser state, unless you take special precautions to unwind the stack correctly (which is what the module does for you).

Comment on Re^3: substitute with recursive regexps?
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2015-11-28 01:59 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (737 votes), past polls