in reply to using a scalar in a regex with backslashes
? Well: it printsmy $match = "\\well"; print $match;
So doing\well
is, more or less (apart from the fact that the regex can be altered at runtime), equivalent to writing:my $match = "\\well"; $text =~ s/$match//;
and /\w/ can match any letter, which is the effect you see: match a word character followed by "ell". For your string this deletes the word "well".$text =~ s/\well//;
Conclusion: if you want to match a literal backslash, the regex/string should contain two backslashes, so the source code to produce the string should contain 4:
One way around this is to use qr//:my $match = "\\\\well"; $text =~ s/$match//;
In this case, what you type is what you get — including any present or missing modifiers.my $match = qr/\\well/; $text =~ s/$match//;
p.s. If you load the pattern(s) for a regex from a text file, you won't have this problem, as what is in the file is what will be in the pattern.
|
|---|