Recently i posted a response to someone else's question in SOPW but since i don't know if it'll ever get hit by other monks who might answer my questions (since it turned out to be more questions than answers) i wanted to post something that would be seen. Sorry for the duplication, but i do want these questions answered if possible...

In essence, i looked at someone else's answer and rewrote as a one-liner in File::Find:

#!/usr/local/bin/perl -w use strict; use File::Find; find { wanted => sub { print if /\.pm$/ }, no_chdir=>1} $dir foreach m +y $dir @INC;
However, when looking at @INC, it seems there are subdirectories in there that would be handled by the time we got there, this could produce some duplication and because of disk access, slow things down. So we make a hash of where we've been:
# use strict and the ilk above my %been_at; sub wanted { return if $been_at{$dir}; $been_at{$dir}=1; print if /\.pm$/; } find {wanted => \&wanted, no_chdir => 1} $dir foreach my $dir @INC;
Then the following questions came to mind:
1) is it faster to create the hash than search the directories again (if we ignore duplicate entries)?
2) is it faster to use or not use no_chdir?

@INC is a small search space, but if we generalize this a little to larger unknown search spaces the questions seem a little more potent (to me at least). Since File::Find has to scan the disk it is one of the slower parts of programs and knowing how to use it better would certainly be a Good Thing(tm).

i'm still pretty new to File::Find and these are things i was wondering, please help,

jynx


In reply to Wondering about File::Find by jynx

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.