JadeNB has asked for the wisdom of the Perl Monks concerning the following question:

“Why, yes,” you reply, “one can say in a regex”:

$ perl -E '/(?{ say "See?" })/' See?
“But,” I reply, “what if you want to interpolate a pattern?”
$ perl -E 'use re "eval"; my $a = qr//; /(?{ say("See?") })$a/' Undefined subroutine &main::say called at (re_eval 1) line 1.
Thoughts?

UPDATE: ambrus suggested in the CB to remind the compiler that I want to use 5.010, and that works:

$ perl -E 'use re "eval"; my $a = qr//; /(?{ use 5.010; say "See?" })$ +a/' See?
which solves my problem, but seems strange. Why should the presence or absence of an empty regex require me to add an apparently superfluous use?
UPDATE: ambrus answered that, too. It's because the interpolated regex changes the big regex from a constant that can be compiled at compile time, to something not known to be constant that must be compiled at run time. Ah, well. I was too eager to post. :-)

Replies are listed 'Best First'.
Re: Can't say in a regex?
by ikegami (Patriarch) on Nov 21, 2009 at 18:07 UTC

    Pragmas (including the feature pragma) don't propagate into (?{}) and (??{}). It's a known bug.

    Example of strict and warnings not propagating:

    use strict; use warnings; use re 'eval'; my $re = ''; '' =~ /$re(?{ print(">$x<\n"); })/;
    ><

    Update: Added link and example

      Some further information, it's known in RT as bug 66104, and is on the list of "blocking bugs" for 5.12. But then, it was on the list of "blocking bugs" for 5.10.1 as well.