Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: parse file name

by ccn (Vicar)
on Sep 22, 2009 at 17:26 UTC ( #796771=note: print w/ replies, xml ) Need Help??


in reply to parse file name

see File::Spec

use File::Spec; my ($volume, $directories, $file) = File::Spec->splitpath( $path ); my ($extension) = $file =~ /\.([^\.]+)$/;


Comment on Re: parse file name
Download Code
Re^2: parse file name
by moritz (Cardinal) on Sep 22, 2009 at 17:35 UTC
    Note that the notion of a "file extension" is a rather vague concept. For example in perl-5.10.1.tar.gz I would consider the .tar.gz to be the extension.

    So if you want to DWIM, you'd have to keep a list of known file extensions that contain a dot, and special case them.

      Or you could consider it to be a recursive definition, so that .gz is the extension of the perl-5.10.1.tar, and .tar is the extension of perl-5.10.1.

      6 of one, 1/2 dozen of another.

      --MidLifeXis

      Please consider supporting my wife as she walks in the 2009 Alzheimer's Walk.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2015-07-03 07:56 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 (49 votes), past polls