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?


In reply to How do you make File::Find a bit less ugly? by qazwart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.