qazwart has asked for the wisdom of the Perl Monks concerning the following question:
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.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";
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:
So, what is the best way to use Find::File?while ($file = File::Find::find(@directoryList)) { if (@wantThis) { print "Here's a file I want: $file\n"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How do you make File::Find a bit less ugly?
by wfsp (Abbot) on Jun 13, 2006 at 16:28 UTC | |
Re: How do you make File::Find a bit less ugly?
by davorg (Chancellor) on Jun 13, 2006 at 16:18 UTC | |
Re: How do you make File::Find a bit less ugly?
by merlyn (Sage) on Jun 13, 2006 at 22:57 UTC | |
by adrianh (Chancellor) on Jun 14, 2006 at 08:24 UTC | |
Re: How do you make File::Find a bit less ugly?
by ptum (Priest) on Jun 13, 2006 at 16:28 UTC | |
Re: How do you make File::Find a bit less ugly?
by graff (Chancellor) on Jun 14, 2006 at 03:43 UTC | |
by bart (Canon) on Jun 14, 2006 at 08:06 UTC | |
by parv (Parson) on Jun 15, 2006 at 01:49 UTC | |
Re: How do you make File::Find a bit less ugly?
by bart (Canon) on Jun 14, 2006 at 08:08 UTC |