
Symbols in patterns interpolated *recursively*?
Quote:
> Subject: Symbols in patterns interpolated *recursively*?
That is not what is happening.
There is only one round of interpolation on the m//, the string
resulting from the interpolation is further processed by
the regex engine.
Quote:
> Sorry. I originally posted on comp.lang.perl.misc. Then someone
> encouraged me to post here because it appeared to be a serious
> question about how the Win32 port of Perl handles patterns invoving
> variables with backslashes.
There is nothing win32-specific in your problem as far as I can tell.
Quote:
> I was trying to compare Windows paths using patterns in an Active
> State Perl 5.6.1 script running on Win2000ProSP3. It appears to me
> that the backslashes in the content of a variable initialed with a
> path doesn't work in a pattern.
If you use forward slashes in the paths, then you don't need
to be concerned with backwards slashes at all. :-)
Forward slashes work fine as the directory separator on Windows.
It is only the _command interpreter_ that demands backwards ones
(because forward ones are used for something else).
Quote:
> I created the followed test script in which all four patterns should
> match, IMHO. If the initial content has no backslashes or a pair, the
> patterns match. But the two cases that have a single backslash fail.
> Is this a Perl bug or am I in error?
You are in error.
Quote:
> my $ABC_DEF = "abc\\def";
If you really need to work with backslashes, then using single quotes
instead of doubles will make your life easier.
Quote:
> $_ = $ABC_DEF;
> print "\$ABC_DEF " .
> (/^$ABC_DEF$/? "matches" : "does not match") .
> " \"$ABC_DEF\"\n"; # Doesn't match; why?
The pattern is: abc\def
The string to match against is: abc\def
Pattern requires an "a" followed by a "b" followed by a "c"
followed by a digit character...
The string has no digit characters in it, so the match must fail.
You can fix it by calling quotemeta() on $ABC_DEF before doing
the match, or by:
/^\Q$ABC_DEF\E$/
But disguising a test for equality as a pattern match is
obfuscation, so don't do that in a serious program:
( $_ eq $ABC_DEF ? "matches" : "does not match") .
--
Tad McClellan SGML consulting
Fort Worth, Texas
.