Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • splitext is cleaner? (Score:3, Informative)

    by da (1525) on 2003.09.03 12:22 (#23797) Homepage Journal
    From the python docs [], it appears that os.path.splitext will always assume the extension contains at most one period, which according to p. 328 of Perl Cookbook (1st ed. :-) is just why File::Basename requires a regular expression: Consider ".tar.gz"- is the extension ".tar", ".gz.", or ".tar.gz"? By specifying the pattern, you control which of these you get.

    So yes, the default for python looks cleaner; but it's less flexible. In the best of all worlds: perhaps File::Basename::fileparse should default to the pattern "\..*" to be more DWIMy.

    Come to think of it, is File::Basename that fugly as-is? Wouldn't something like:

    ($junk, $component, $flavour) = fileparse($file, "\..*"); look clearer than:

    ($component, $flavour) = $file =~ m{^.*/(.*)(\..*)$}; # extract suffix

    (speaking as somebody who knows no python; and hasn't used fileparse much. Maybe you had a reason to avoid fileparse I didn't see!)


    -DA []