Skip to content

Instantly share code, notes, and snippets.

@sdasgup3
Created May 12, 2017 08:24
Show Gist options
  • Save sdasgup3/eabf150fd1e7c9bf01679f569602ec24 to your computer and use it in GitHub Desktop.
Save sdasgup3/eabf150fd1e7c9bf01679f569602ec24 to your computer and use it in GitHub Desktop.
Split filepath into (parent directory, basename, extension)
# 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