Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: how to overcome Win32 path delimiter in s///?

by The Mad Hatter (Priest)
on Oct 14, 2004 at 23:32 UTC ( #399358=note: print w/replies, xml ) Need Help??


in reply to how to overcome Win32 path delimiter in s///?

Wrap $path in \Q and \E (which escapes metachars) like so...

my $file = 'c:\some\win32\path\mydir\file.txt'; my $path = 'c:\some\win32\path'; (my $file_nopath_noext = $file) =~ s/\Q$path\E\\(.*)\.txt/$1/; print $file_nopath_noext."\n";

See perldoc perlre.

Replies are listed 'Best First'.
Re^2: how to overcome Win32 path delimiter in s///?
by bsdz (Friar) on Oct 14, 2004 at 23:41 UTC
    that's precisely what I was hoping for. I failed to consider \Q..\E metacharacter manipulation. Thank you
      The function quotemeta will acomplish the same thing if you use it on the value before it is interpolated by the regex.

      If you are particularly worried about forward slashes then you can just use an alternate character to delimit the parts of the substitution.
      e.g. single char s!!! or paired s()()

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://399358]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2016-12-06 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (118 votes). Check out past polls.