You have to remember that even though you are using double-backslashes in
your variable assignment, by the time it gets to the regex, $s2 contains
'c:\root\sub1\'.  So what you are telling Perl is:  $s2 =~
s/c:\root\sub1\sub2\myfile.dat//gi, which doesn't have any backslashes at
all, just some escaped characters.  use the \Q switch to fix this.

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

-----Original Message-----
From: rAuL [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 19, 2002 9:07 AM
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