qazwart has asked for the wisdom of the Perl Monks concerning the following question:

I'm not a big fan of File::Find. To use it, I usually create a wanted function, load up an array with the stuff I want, and then process the array in my main block of code:
use File::Find; [...] my @fileList; find(\&wanted, qw($myDirectory)); sub wanted { if (-f $File::Find::name) { push(@fileList, "$File::Find::name) } } print "You've found " . join("\n\t", @fileList) . "\n";
To me, this just isn't very pretty because my @fileList array is being treated as being global to the &wanted funciton. Plus, it is slow because I have to wait for my array to fill up before I can use it.

The way around this is to put most of my file processing code with in the wanted function which also seems just as ugly since 90% of my script will end up inside wanted.

Maybe I really don't know the correct way to use File::Find. The Perl POD on this module concentrates more on find2perl than on using this module. However, it doesn't appear to be another method for File::Find.

Just how are you suppose to use File::Find? Most of the comments I've seen concentrate on automatically generating the "wanted" array. To me, this really isn't the problem. Heck, I'd be happy if File::Find simply walked the file tree, and I had to manually take the output and figure out if I wanted it or not. Something like this:

while ($file = File::Find::find(@directoryList)) { if (@wantThis) { print "Here's a file I want: $file\n"; } }
So, what is the best way to use Find::File?