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

Re: how to remove everything before last slash in perl?

by muba (Priest)
on Jun 23, 2012 at 20:08 UTC ( #978014=note: print w/ replies, xml ) Need Help??


in reply to how to remove everything before last slash in perl?

Another approach, if you really want to use a regex, would be to capture just that part that you're interested in:

my $somestring = "y:/home/lib/directory/piano_book"; ($somestring) = $somestring =~ m#([^/]+)$#; print $somestring; __END__ piano_book

Update: or just to show that always TIMTOWTDI:

my $somestring = "y:/home/lib/directory/piano_book"; my $idx = rindex($somestring, "/"); $somestring = substr($somestring, $idx+1); print $somestring;


Comment on Re: how to remove everything before last slash in perl?
Select or Download Code
Re^2: how to remove everything before last slash in perl?
by Tux (Monsignor) on Jun 23, 2012 at 22:58 UTC

    More than one way?

    my $filename = (split m{/} => $full_path)[-1];

    I agree however that File::Basename is way better, as it also deals with filesystems other than Unix-like that use a forward slash.


    Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-08-29 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls