Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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
Replies are listed 'Best First'.
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 rifling through the Monastery: (8)
As of 2015-07-30 00:17 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 (269 votes), past polls