in reply to matching the + character
Single quoting and character classes are all very well if you're dealing with test data, but i think we can assume you're not really going to be testing whether two strings you just typed in match. In the general case, if you want to find out whether $var2 is contained in $var1, and $var2 might contain something that will be unhelpfully interpolated, use this:
$match if $var1 =~ /\Q$var2\E/;\Q..\E is a special case of the quotemeta function, which automatically escapes non-alphanumerics (but not $ or @, so you still get variable interpolation).
Not the first time this has come up, by the way. Reading perlre will help.
update: followed own sanctimonious advice, read perlre, changed description of quotemeta :(
|
---|