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

Greetings. I am having a problem with a program I am writing; it needs to parse an expression with a prefix, a postfix, and one of several values in between. I thus have a regex which does this:
my $ex = ($prel . '(' . join("|",map { '\Q' . $_ . '\E' } keys %stuff) + . ')' . $postl);
and prel and postl both already are regexen. However, when I attempt to execute it, I get:

nested *?+ in regexp at ./foo line 42, <> chunk 1.

What's going on? There aren't any nested *?+ as far as I can tell.

Replies are listed 'Best First'.
Re: Regex
by japhy (Canon) on Apr 06, 2001 at 21:01 UTC
    Have you tried looking at $ex? And I should tell you now, you meant to be doing:
    join '|', map quotemeta($_), keys %stuff; # or join '|', map "\Q$_\E", keys %stuff; # \E not needed


    japhy -- Perl and Regex Hacker
      Yes, I have. It came out looking okay.

      I had, however, forgotten about quotemeta. Thanks!

Re: Regex
by runrig (Abbot) on Apr 06, 2001 at 21:02 UTC
    It would really help to know what the values of the variables are, and the keys of %stuff.