Watch out! dirname()
is deliberately dumb to emulate the dirname
shell command. It is not so much "give me the directory part of this file path" as "give me all but the last part of this path". Why is that important?
my $dir = "/foo/bar/"; # obviously a directory
print dirname($dir); # prints /foo
This is fine, just so long as you realize that dirname
does not return the dirname.
If you want the above to return /foo/bar/
you're better off using File::Spec.
use File::Spec;
my($vol,$dir,$file) = File::Spec->splitpath($path);