Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Re: Re: Re: Re: convert windows path

by George_Sherston (Vicar)
on Nov 06, 2001 at 15:33 UTC ( #123550=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: Re: convert windows path
in thread convert windows path

So... what? you want to get a scalar var containing the filename? So you can print it out or something?

If that's what you want, There's A Lot More Than One Way To Do It. Don't let anyone around here hear you say "Perl doesn't let me search and replace..." ! If anyone can search and replace it's Perl.

Assuming you have
my $filepath = 'c:\somedir\file.ext'
and you want to get
$filename eq 'file.ext'
$filepath =~ /([\w|\.]*)$/; my $filename = $1;
Oughta do it - i.e. capture the longest possible string at the end of the filepath that is either a word character (alpha-num or _) or a dot. Or if you think there might be non-word characters in the file name, $filepath =~ /([^\\|^\/]*)$/; - capture the longest string at the end that doesn't have either a "\" or a "/".

I'm no regex guru, so there may be obscure pitfalls in either of these, or a neater way to do it... but that's what I'd do.

Of course, I may have completely mis-understood your question again :)

George Sherston

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2022-01-26 17:05 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (69 votes). Check out past polls.