[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [FWP] Filthy Secrets of the regex engine



> In a regex with an interpolated variable, such as
> 
>         /foo($a)bar/
> 
> the user is not allowed into interpolate (?{CODE}) items unless the
> "use re 'eval'" pragma is in scope.  You are of course allowed to
> write
> 
>         /foo(?{CODE})($a)bar/
> 
> and this is OK as long as the interpolated $a does not contain
> (?{CODE}) items.
> 
> The way this is implemented is that the regex engine counts up the
> number of appearances of (?{CODE}) items before and after
> interpolation, and throws a fatal run-time error if the number
> afterwards is larger:
> 
>         Eval-group not allowed at runtime...
> 
> You might expect that "use re 'eval'" simply disables this check, but
> you would be wrong.  Instead, the "use re 'eval'" pragma fakes up the
> 'before' count so that it appears that the regex originally contained
> 4,294,967,295 appearances of (?{CODE}) items.
> 
> (The code is at pp_ctl.c:114 in 5.6.0, should you want to visit it.)

Ummm.... thanks, I think. :)

This kind of rates right up there with the truth about Santa.  Good to know,
but painful to learn...
-- 
Mike

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe