Skip to content

Instantly share code, notes, and snippets.

@EvanK
Created April 22, 2011 11:22
Show Gist options
  • Save EvanK/936466 to your computer and use it in GitHub Desktop.
Save EvanK/936466 to your computer and use it in GitHub Desktop.
Perl `basename` and `dirname` module-free implementations
# WHY would we need this? For a situation where loading File::Basename isn't possible
# For example, in a BEGIN block, to tinker with @INC.
sub basename {
my $file = shift;
$file =~ s!^(?:.*/)?(.+?)(?:\.[^.]*)?$!$1!;
return $file;
}
sub dirname {
my $file = shift;
$file =~ s!/?[^/]*/*$!!;
return $file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment