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

A script that I am using is bombing out with a "Nested quantifiers before HERE mark in regex m/^libg++ << HERE .dll$/ at d:\tmp\script.pl line 503."

the code that is at line 503 looks like:

if ( grep {/^ITEM$/} @ARRAY ) {

Does anyone have any advice on how to deal with this, for example can grep's behavior be modified to deal with multiple plus signs in what it is matching, etc.
If it helps, the ARRAY array contains names of files that we want to weed out, i.e., it $ITEM matches an entry in @ARRAY, then we reject it.

Thanks, Kevin

Replies are listed 'Best First'.
Re: Nested Quantifier Headaches
by thelenm (Vicar) on Jun 05, 2003 at 16:08 UTC
    Since the + sign is special inside regexes, you'll need to escape it with a backslash. Since the + sign is inside a variable you're using in your regex, you can use the special \Q and \E tokens to escape any special characters in the variable, like this:
    if ( grep {/^\Q$ITEM\E$/} @ARRAY ) {

    A more extensive explanation of \Q and \E can be found in the perlre documentation.

    Update: Just realized that you may be better off not even using a regex for this. Since you're looking for an exact string match, you can also use eq, like this:

    if ( grep {$_ eq $ITEM} @ARRAY ) {

    -- Mike

    --
    just,my${.02}

      I used the /Q and the /E, this worked well. Thank you for the input and fast response.

      Kevin