I'm using File::Find to get a list of files from a base directory. I then want to find files that are in certain key directories that are kept in scalar variables. But the regular expression will not work correctly as the backslashes seem to cause funnies.
For example, the following two code examples would be expected to give the same output:-
example 1.my $match = "\\well"; my $text = "\\well don't you know it"; $text =~ s/$match//; print "$text\n"; example 2. $text = "\\well don't you know it"; $text =~ s/\\well//; print "$text\n";
You would expect to see: don't you know it
But example 1 gives: \ don't you know it
It appears as if the regex is compiled to take the \\ to mean \ but compares against the string which keeps the original \\.
This really messes things up if you want to specify a directory structure (eg c:\\windows) for dealing with files, but then want a regex of the same value; it would have to be defines as c:\\\\windows.
Does anybody know what is going on here and is there a way around it.
Humbly
Tim
In reply to using a scalar in a regex with backslashes by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |