You can use \Q and \E to tell the regex to not do any other interpreting of 
characters within a variable:

my $s1 = "c:\\root\\sub1\\sub2\\myfile.dat";
my $s2 = "c:\\root\\sub1\\";

$s1 =~ s/\Q$s2\E//gi;

printf "%-s\n", $s1;

Output:
sub2\myfile.dat

Wags ;)


-----Original Message-----
From: rAuL [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 19, 2002 09:07
To: [EMAIL PROTECTED];
[EMAIL PROTECTED];
[EMAIL PROTECTED]
Subject: Pattern Matching on Win32 Pathnames



I am trying to do the following substitution

$s1 = "c:\\root\\sub1\\sub2\\myfile.dat";
$s2 = "c:\\root\\sub1\\";

$s2 =~ s/$s2//gi;

The result I want is "sub2\\myfile.dat".  In other words, I want to locate ANY portion 
of the path in the source string and sub it with something else, such as another path 
specification, NULL, etc.

My script dies because regex does not like the backslash character?  I could convert 
them to UNIX style forward slashes but was wondering if there was any other way.

Thanks for your help.

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to