more useful options | |
PerlMonks |
Re^3: A (non) reg-ex questionby hv (Prior) |
on Mar 20, 2006 at 23:51 UTC ( [id://538088]=note: print w/replies, xml ) | Need Help?? |
I think my edition of the Camel predates qr{} so I doubt I have that example to hand, but I'd expect it to be much the same except that balanced parens can usually look like "()(())(()())" and the like. Except for certain special optimisations, a regular expression is always traversed from left to right. The critical thing to stop infinite recursion is to ensure that at least one character must be matched each time before recursing, ie that there be something to the left of the nested $re. In this case, ($re = qr{(?:0(??{$re})1)?}), we require a '0' to be matched before recursing. So "0011" =~ /^$re\z/ will be executed like:
Similarly, you could (foolishly) replace /0+/ with a recursive regexp like: which would work, but the following would fall into infinite recursion:
Hope this helps, Hugo
In Section
Seekers of Perl Wisdom
|
|