Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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?
[dazz]: Hi I have grabbed an image from an IP camera with Image::Grab. I then want to pass that image object to a subroutine where I do a read-only test on the image with Image:Magick.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2017-03-27 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (317 votes). Check out past polls.