SPUG: Metacharacters in variables in regular expressions

Ken Clarke k_clarke at perlprogrammer.net
Mon Jan 12 16:07:22 PST 2009


> So this is what I want, right?:
>
> if($some_earlier_var =~ /\Q$answer\E/) { ### destroy the universe ### }

Yes.  You likely also want to anchor it so the match is not in the middle of 
the string, which would make it:

    /^\Q$answer\E\z/

>> Ken Clarke
>> Contract Web Programmer / E-commerce Technologist
>> www.PerlProgrammer.net
 



More information about the spug-list mailing list