in reply to Dissecting a complete pathname to a file

Take a look at File::Basename; it provides fileparse(), a function that splits a full specification into three parts: (base-name, path, suffix). But, it doesn't "capture and *expand* the current directory" when fed a '.'. For that, you have to have a special case:
use strict; use warnings; use File::Basename; use Cwd; my $file_name = './hello.world'; # Insert your file-name gathering logic here # Place the results in $file_name. my ($base_name, $path, $suffix) = fileparse($file_name); if ($path =~ /\./) { $path = cwd(); }
Note: Written but not run past a Perl interpreter....

----
I Go Back to Sleep, Now.

OGB

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

    Why handle only one very specific relative path? Fix:

    use strict; use warnings; use File::Basename qw( fileparse ); use File::Spec::Functions qw( rel2abs ); my $file_path = './hello.world'; my ($file_name, $dir_path) = fileparse(rel2abs($file_path)); print("dir path: $dir_path\n"); print("file name: $file_name\n");