Created
May 12, 2017 08:24
-
-
Save sdasgup3/eabf150fd1e7c9bf01679f569602ec24 to your computer and use it in GitHub Desktop.
Split filepath into (parent directory, basename, extension)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assumpsion: no '.' in the filepath | |
sub split_filename { | |
my $arg = shift @_; | |
if("" eq $arg) { | |
return ("", "", ""); | |
} | |
my ($dir, $basename,$ext) = ("", "", ""); | |
my @components = split (/\//, ${arg}); | |
my $filename = $components[@components -1]; | |
if(@components > 1) { | |
$dir = join('/', @components[0..@components-2]); | |
} | |
@components = split (/\./, ${filename}); | |
$basename = $components[0]; | |
$ext = $components[1]; | |
return ($dir,$basename,$ext); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment