in reply to Dissecting a complete pathname to a file

consider:
use File::Spec; my ($vol, $path, $file) = File::Spec->splitpath( File::Spec->rel2abs($filespec) );
(rel2abs uses Cwd::cwd in this case)

Replies are listed 'Best First'.
Re^2: Dissecting a complete pathname to a file
by ikegami (Patriarch) on Feb 27, 2007 at 23:53 UTC

    Not quite there. Then you have to join $vol and $path together, and File::Spec doesn't provide the means to do that. You might say "But catpath!", but using catpath without a file name is undocumented, and it leaves an errant trailing slash on my system. Rather than using the fragile

    use File::Spec::Functions qw( splitpath catpath rel2abs canonpath ); my ($v, $p, $file_name) = splitpath(rel2abs($file_path)); my $dir_path = canonpath(catpath($v, $p));

    use the module designed for the task at hand, File::Basename.

    use File::Basename qw( fileparse ); use File::Spec::Functions qw( rel2abs ); my ($file_name, $dir_path) = fileparse(rel2abs($file_path));