Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: getting picky with File::Find

by RichardK (Parson)
on Apr 08, 2014 at 23:02 UTC ( #1081582=note: print w/replies, xml ) Need Help??

in reply to getting picky with File::Find

I think File::Find::Rule is easier to use so here's my attempt, using glob to get just the abc* directories. This ignores everything below baby/dead directories.

use v5.18; use warnings; use autodie; use File::Find::Rule; my $rule = File::Find::Rule->or( File::Find::Rule->name('baby','dead') ->directory() ->prune() ->discard() , File::Find::Rule->file->name('list.dat') ); my @files = $rule->in( glob('abc*') ); say "****************"; say for @files;

Replies are listed 'Best First'.
Re^2: getting picky with File::Find::Rule less typing find/rule
by Anonymous Monk on Apr 09, 2014 at 02:37 UTC

    File::Find::Rule exports rule/find by default, so less typing ; I add find/rule to export list for documentation purposes

    #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; use File::Find::Rule qw/ rule find /; my @dirs = find( qw/ directory name abc* in . /); dd( \@dirs ); my $nobaby = rule( name => [ 'baby', 'dead' ], qw/ prune discard/ ); my $list = rule( file => name => 'list.dat', ); my @files = find( not => $nobaby , any => $list, in => \@dirs, ); dd( \@files ); @files = rule()->or( ## !IMPORTANT NOTE discard before prune with rule()/find() rule( name => [ 'baby','dead' ], qw/ directory discard prune /), rule( qw' file name list.dat ') )->in( find( qw/ directory name abc* in . maxdepth 1 /), ); dd( \@files ); __END__ $ perl ["abcdefg"] ["abcdefg/coy/abu/list.dat", "abcdefg/coy/dabie/list.dat"] ["abcdefg/coy/abu/list.dat", "abcdefg/coy/dabie/list.dat"]
    $ findrule abcdefg abcdefg abcdefg/coy abcdefg/coy/abu abcdefg/coy/abu/list.dat abcdefg/coy/baby abcdefg/coy/baby/list.dat abcdefg/coy/dabie abcdefg/coy/dabie/list.dat abcdefg/coy/dead abcdefg/coy/dead/list.dat

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1081582]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-05-22 06:29 GMT
Find Nodes?
    Voting Booth?