Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: extract file name from a dynamic path

by ikegami (Patriarch)
on Sep 06, 2008 at 17:13 UTC ( [id://709528]=note: print w/replies, xml ) Need Help??


in reply to extract file name from a dynamic path

Use File::Basename's basename. It's part of Perl.

Replies are listed 'Best First'.
Re^2: extract file name from a dynamic path
by alexm (Chaplain) on Sep 07, 2008 at 01:41 UTC

    While writing my last CUFP I found a warning about basename in File::Basename:

    This function is provided for compatibility with the Unix shell command basename(1). It does NOT always return the file name portion of a path as you might expect. To be safe, if you want the file name portion of a path use fileparse().

    I'd like to see an example of this, since I can't figure out what can be wrong with basename.

      Just keep reading, it says
      C<basename()> returns the last level of a filepath even if the last level is clearly directory. In effect, it is acting like C<pop()> for paths. This differs from C<fileparse()>'s behaviour. # Both return "bar" basename("/foo/bar"); basename("/foo/bar/");

        I was blind when I read that, thanks :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2026-01-19 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (123 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.