Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2018-02-20 16:13 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (272 votes). Check out past polls.