Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Regex for ignoring paths

by dbuckhal (Hermit)
on Oct 31, 2018 at 18:05 UTC ( #1225010=note: print w/replies, xml ) Need Help??


in reply to Regex for ignoring paths

Another simple, fast solution, based on a snippet found on page 23 of Dominus's book, Higher-Order Perl:

sub short { my $path = shift; $path = s{.*/}{}; $path; }
...or as a callback:
my $short = sub { my $path = shift; $path =~ s{.*/}{}; $path; };
Callback example:
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...

Replies are listed 'Best First'.
Re^2: Regex for ignoring paths
by Anonymous Monk on Oct 31, 2018 at 18:12 UTC
    how does this help the OP?
      Stripping the path? ...or did I misinterpret the OP? If so, then move along, not much to see here... :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1225010]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2019-10-21 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?