use File::Basename;
my $path = "a/b/c/d";
my $dirpath = basename ($path);
my $basepath = dirname ($path);
my $base_basepath = dirname ($basepath);
my $dir_dirpath = basename ($basepath);
print "$dir_dirpath/$dirpath\n";
I want c/d to be printed (i.e the list dir/filename). Is the above the best way to do that? The above obviously works but I somehow don't like it. Is there a better/cool/efficient way to do it? Something like a regex match??
Actually, that program just does a part of what I really want it to do. These are the different use cases and what the expected result is :
a/b/c/d => c/d d
b/c/d => c/d d
/c/d => c/d d
c/d => c/d d
/d => d
d => d