PerlFunc: file_parts()

Not perfect, but it will return a breakdown of the various parts (path, name, extension) of a given file.

sub file_parts {
    my $file = shift();
    my $ret;

    #print "File: $file\n";

    if ($file =~ /(.*\/)?(.*?)\.(.*)/) {
        $ret->{'path'} = $1;
        $ret->{'name'} = $2;
        $ret->{'ext'} = $3;
    }

    return $ret;
}
Leave A Reply
All content licensed under the Creative Commons License