http://www.perlmonks.org?node_id=308919


in reply to Matching brackets in Regular Expression

I don't understand...what makes the $stub scalar volatile?

Replies are listed 'Best First'.
Re: Re: Matching brackets in Regular Expression
by jweed (Chaplain) on Nov 21, 2003 at 18:28 UTC
    The problem is that this scalar $stub is volatile and it also contains a little bracket...

    I believe that though he listed that bob(scalar), it should be bob[scalar] as the description lists. In this case it would be interpreted as a character class instead of a string. \Q and \E would backslash these brackets.

    In it's current form, there's really no conflict unless the string is something like bob(??{print $hi}).



    Who is Kayser Söze?
    All code is untested unless I say so.

      Except that the parens () will be used for grouping and capturing by the regex, and so won't match the literals in the string;

      perl -e '$s = q|b(s)|; print "without quotemeta" if $s =~ /$s/; print + "with quotemeta" if $s =~ /\Q$s\E/;' with quotemeta

      qq