in reply to Spurious re 'eval'; warning ?

The error indicates the regex compiler didn't think it had everything it needed to create the regex complete with eval contents at compile time. The first thing here is that your inclusion of $_ defers the overall regex compilation time until runtime due to interpolation. At that point its just a distinction between whether "(?{1})" is precompiled or not for (??{ ... }).

My guess is that you managed to stave off the runtime-eval error by tricking perl with the qr// operator. In reality that qr// wasn't compiled until the contents of the (??{ ... }) were being parsed/compiled at runtime. The difference is probably that the (?{1}) was considered safe by qr// because it was during *a* compiletime. That really doesn't sound like a correct behaviour to me. Bug?

Replies are listed 'Best First'.
Re: Re: Spurious re 'eval'; warning ?
by bsb (Priest) on Aug 25, 2003 at 00:24 UTC
    My guess is that you managed to stave off the runtime-eval error by tricking perl with the qr// operator

    Maybe. Although putting another eval string around it doesn't seem to change anything:

    $ perl -Mre=eval -e '/ (??{ eval "qr<(?{1})>" }) $_ /x' $ perl -Mre=eval -e '/ (??{ eval "q<(?{1})>" }) $_ /x' Eval-group not allowed ...
    perlre has an explicit distinction for interpolating qr// objects (under (?{}) instead). The problem is that I do use re "eval", but perl seems to forget. It does seems a little bug-ish, I'll perlbug it.

    perlre: (?{ })
    For reasons of security, this construct is forbidden if the regular expression involves run-time interpolation of variables, unless the perilous "use re 'eval'" pragma has been used (see re), or the variables contain results of "qr//" operator (see "qr/STRING/imosx" in perlop).

      And of course, the bug would be that perl isn't throwing the error but should.

        Too late... I perlbug-ed it the other way before reading your reply, otherwise I would've waited.

        I re-read your posts and the relevant man pages but still don't understand why it should be an error. "use re qw(eval)", to me, means anything goes, security be damned.

        If you convince me otherwise then I'll track down my bug report and fix it up. If you don't then the people fixing the bug can decide.

Update: Re: Spurious re 'eval'; warning ?
by bsb (Priest) on Aug 28, 2003 at 01:47 UTC
    Date: 27 Aug 2003 12:47:56 -0000 From: Rafael Garcia-Suarez (via RT) Subject: Re: [perl #23569] use re 'eval'; lost in (??{"(?{1})"}) Brad Bowman (via RT) wrote: > This code generates an "Eval-group ..." error despite the presense > of "use re qw(eval)". > > $ perl -Mre=eval -e '/ (??{ "(?{1})" }) $_ /x' > Eval-group not allowed at runtime, use re 'eval' in regex m/(?{1})/ +at -e line 1. This is apparently just another instance of the compiler hints not bei +ng propagated to eval-strings (except "integer", "strict refs" and a few others). This can't be fixed non-kludgily without an overhaul of the h +int system.