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

This snippet produces a core dump. It's a simple regex with another regex embedded in a (?{}) section. Am I doing something that just isn't supposed to be done? If this is just a bug then I can report it later but I don't know that yet and thought I'd ask first.

' 1a2' =~ m/(.(?{$char = substr($_,pos(),1); print "$char "; print $char =~ m|\d| ? "digit\n" : "not digit\n"; }))+/;
__SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;

Replies are listed 'Best First'.
Re: Using regexes inside of (?{})
by pg (Canon) on Dec 08, 2002 at 18:24 UTC
    There is no need to report this, please check this web page: cannot use regexp inside (?{})

    I pasted a piece of it here, and hightlighted one sentence, which gives the why:

    "Regex Engine Reentrancy
    Stéphane Payrard reported that Perl dumps core if you try to do a regex match inside of a (?{...}) expression. This did not come as a big surprise seeing as the regex engine is not reentrant. (It uses several global variables.)
    Hugo van der Sanden: Making the regexp engine reentrant should fix the problem.
    Jarkko Hietaniemi: This is a bit like saying, "Stopping the wars should bring the world peace."
    Stéphane suggested making it a fatal error in the meantime, but no patch was offered.
    Somewhere in the discussion, Jesus Quiroga mentioned that he was working on a replacement for perlre.pod, including a tutorial and some examples. It's about time!"

Re: Using regexes inside of (?{})
by theorbtwo (Prior) on Dec 08, 2002 at 17:36 UTC

    I'm fairly certian it's a known WONTFIX bug that the perl5 regex engine is non-reentrent. (IE it's considered unfixable without a near complete rewrite.) The perl6 one is being written from scrach, and explicitly will be, but it may or may not be retrofitable.


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      Thanks for confirming that. It's just not documented perlre that the engine isn't reentrant.

      __SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;