Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: getting picky with File::Find

by RichardK (Priest)
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;


Comment on Re: getting picky with File::Find
Download Code
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 ffffindrule.pl ["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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-09-21 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (175 votes), past polls