Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: using a scalar in a regex with backslashes
by broquaint (Abbot) on Oct 09, 2002 at 16:42 UTC | |
|
Re: using a scalar in a regex with backslashes
by bart (Canon) on Oct 09, 2002 at 18:50 UTC | |
|
Re: using a scalar in a regex with backslashes
by BrowserUk (Patriarch) on Oct 09, 2002 at 17:11 UTC | |
|
Re: using a scalar in a regex with backslashes
by sauoq (Abbot) on Oct 09, 2002 at 18:59 UTC |