Another simple, fast solution, based on a snippet found on page 23 of Dominus's book, Higher-Order Perl:
...or as a callback:sub short { my $path = shift; $path = ˜ s{.*/}{}; $path; }
Callback example: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
Edit: shortened output a bit...
In reply to Re: Regex for ignoring paths
by dbuckhal
in thread Regex for ignoring paths
by Amblikai
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |