in reply to Spurious re 'eval'; warning ?

I'm far from considering myself well-informed on RegEx matters, but the way I see it, the RegEx engine expects real code in (?{ code }) and (??{ code }) constructs and not a RegEx. See perlre for further reference. The reason why the fourth example works would then be that you told the compiler the 'code' was a RegEx. Just use one alternative at a time and you'll be fine.
Hope this helped, CombatSquirrel.

P.S.: What are you trying to do with your code? I don't see the sense of embedding one of the above constructs into the other. Maybe we can find a work-around if you give specifics of your problem.

Replies are listed 'Best First'.
Re: Re: Spurious re 'eval'; warning ?
by bsb (Priest) on Aug 24, 2003 at 12:58 UTC
    What are you trying to do with your code?

    I'm just playing around.

    Returning a qr// regex is a work around.

    I read perlre and re, and I consider "(?{1})" a valid return value. You can use other strings without a problem:

    $ id|perl -nle 'print /( (??{ q[uid=\d+] }) )/x' uid=1000
    This snippet from perlre doesn't specify a regex ref or string (although it is pretty vague). The example which follows in the man page uses a recursive qr// definition (so does return a qr// object).

    From perlre:
    (??{ code })
    ... The result of evaluation is considered as a regular expression and matched as if it were inserted instead of this construct.

      My apologies, seems as though you were right. However, I found an interesting section in perl5005delta:
      %s: Eval-group not allowed at run time
      (F) Perl tried to compile a regular expression containing the (?{ ... }) zero-width assertion at run time, as it would when the pattern contains interpolated values. Since that is a security risk, it is not allowed. If you insist, you may still do this by explicitly building the pattern from an interpolated string at run time and using that in an eval(). See perlre/(?{ code }).
      Perl just doesn't seem to like what you're doing and stops it ;-).
      Hope this helps.
      Cheers, CombatSquirrel.

      Update: fixed typos.

        I noted elsewhere that it was probably wrong of perl to *not* throw an error when bsb prepended the 'qr' onto the internal regex. So you're exactly right.