in reply to Grep file out of directory and read into array

I find File::Find::Rule much easier to use that File::Find and for this case even has a grep method.

So you code to get the file-names containing your pattern(s) could look something like this (untested )

my @files = File::Find::Rule->file() ->name( '*.dpt' ) ->grep( $pattern ) ->in( $dir );

Replies are listed 'Best First'.
Re^2: Grep file out of directory and read into array (find/rule)
by Anonymous Monk on Dec 08, 2014 at 19:04 UTC
    Same deal, less(?) typing :) also untested
    use File::Find::Rule qw/ find rule/; my @files = rule()->file() ->name( '*.dpt' ) ->grep( $pattern ) ->in( $dir );
    or even
    my @files = find( file => name => '*.dpt', grep => qr/pattern/, in => $dir, );
    or even
    my @files = rule( file => name => '*.dpt', grep => qr/pattern/, )->in( + $dir );
    or even an "iterator" version like foreach(@files) but without keeping a list of all the files in memory
    rule( file => name => '*.dpt', grep => qr/pattern/, )->exec(sub { my( $shortname, $path, $fullname ) = @_; ## do something with $fullname :) return !!0; # discard filename } ) ->in( $dir );