Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: remove directory path

by prasadbabu (Prior)
on Mar 02, 2006 at 13:10 UTC ( #533872=note: print w/ replies, xml ) Need Help??


in reply to remove directory path

You need to take a look at File::Basename

or simply with regex

$file = "/opt/local/bin/zap.exe"; $file =~ s|.*/||s; print $file; output: zap.exe

updated: As per frodo72 suggestion. Thanks frodo72

Prasad


Comment on Re: remove directory path
Download Code
Replies are listed 'Best First'.
Re^2: remove directory path
by polettix (Vicar) on Mar 02, 2006 at 15:33 UTC
    The File::Basename approach is better IMHO - more readable, portable and tested.

    In the regex, you're bound to be in some Unix flavour; moreover, it misses files in the root directory, because of the "+". I'd reword it as:

    $file =~ s{.*/}{}s;
    but the better choice remains File::Basename.

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
Re^2: remove directory path
by sen (Hermit) on Mar 02, 2006 at 13:48 UTC

    try this..

    $file = "/opt/local/bin/zap.exe"; print $file = (split(/\//, $file))[-1];
Re^2: remove directory path
by sen (Hermit) on Mar 02, 2006 at 13:47 UTC

    try this..

    $file = "/opt/local/bin/zap.exe"; $file = (split(/\//, $file))[-1]; print $file;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2015-07-28 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (251 votes), past polls