Could someone explain to me why the following prints “fail”? And what the workaround is?
my $test1 = "/k?user";
my $test2 = "/k?user";
if ($test1 =~ m/$test2/) {
print "match";
}
else {
print "fail";
}
If I change $test1 and $test1 to "/k?", the match works.
Clearly it has something to do with text following the ?. But, the variables I am trying to match have question marks in them, and I would rather not have to take everything apart, match the pieces, and then reconstruct everything.
?is a special character in a regex. Use quotemeta: