Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2022-01-20 23:32 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (57 votes). Check out past polls.