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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://399358]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2016-10-22 14:38 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (295 votes). Check out past polls.