in reply to File::Find: Return array of "wanted" files
Note: File::Find's find function takes an array as its 2nd parameter, so foreach (@dirs) isn't needed.
Update: Interesting: I interpreted the OP's if (fgrep { /regex/ } "$file") as a typo (fgrep vs grep) for a check for a regex in the filename. choroba's response below makes better sense of that.use strict; use warnings; use File::Find; my @files; my @dirs = qw(/some /list /of /dirs); sub findstuff { my $file = $File::Find::name; return unless -f "$file"; if (grep { /regex/ } "$file") { print "Found regex in $file\n"; push @files, $file; } } find(\&findstuff, @dirs); print "Results:\n@files\n";
|
---|