sub short {
my $path = shift;
$path = ˜ s{.*/}{};
$path;
}
####
my $short = sub {
my $path = shift;
$path =~ s{.*/}{};
$path;
};
##
##
perl -Mstrict -we '
my $dir = shift or die "missing dir name...\n";
die "not a directory\n" unless -d $dir;
my $short = sub {
my $path = shift;
$path =~ s{.*/}{};
$path;
};
sub dosub {
my $_dir = shift;
opendir my $dh, $_dir or die "could not open $_dir\n";
while ( my $file = readdir($dh) ) {
next if $file eq "." || $file eq "..";
if ( -d "$_dir/$file" ) {
dosub ("$_dir/$file");
} else {
print "full: $_dir/$file\n"; print "shortened: ", $short->("$_dir/$file"), "\n\n\n";
}
}
}
dosub($dir);
' temp01
__output__
full: temp01/subtemp01/subsubtemp01/file01
shortened: file01
full: temp01/subtemp01/subsubtemp02/file02
shortened: file02
full: temp01/subtemp01/subsubtemp03/file03
shortened: file03
full: temp01/subtemp01/subsubtemp04/file04
shortened: file04