Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Interesting...

Honestly, I'd really rather not see yet another implementation of directory traversal in perl. What I think would be the ideal is to have just one implementation (let it stay File::Find, everyone already knows it!), but have that implementation be usable with each of these types of interface:

  1. callbacks
  2. declaratively (by that I mean: my @files = File::Find::find(...); or something similar)
  3. iterator

Presently, File::Find provides 1, directly. File::Find::Rule and its ilk provide 2 (as a wrapper around File::Find... which is great, because that means no one has to replicate the directory traversal code for that). The thing that's missing is a good iterator interface, and, again, that can't be built as a wrapper around File::Find.

So of course, the best possible thing (in my opinion) would be if someone rewrote File::Find so that it (internally) had an iterator interface:

my $finder = File::Find->new($opts, @dirs); while (my $file = $finder->next) { # do stuff }
And then, finally, to change the old familiar File::Find::find(...) to be implemented as a simple wrapper around File::Find's iterator interface:
# simplified a lot, but basically sub find { my ($opts, @dirs) = @_; $opts = wrap_wanted ($opts); my $wanted = $opts->{wanted}; my $finder = File::Find->new($opts, @dirs); while (my $file = $finder->next) { local $_ = $file; local ... # etcetera &$wanted } }
So you'd get:
  • all the benefits of each type of interface
  • the directory traversal written (and optimized and maintained, etc) only once
  • nothing gets broken (all we've done is to refactor and to add new functionality)

Of course, I feel bad demanding this, without volunteering to do it, but honestly, it would create legal complications if I were to do so (I've got one of those contracts where my employer owns everything I do... at least for the moment, but I've been promised that that will change at least somewhat by the end of july). But I still think that the "most best" approach is clear enough that it's worth setting down (even if I'm not going to go off and implement it myself).

------------ :Wq Not an editor command: Wq

In reply to Re^5: When should a wheel be reinvented by etcshadow
in thread When should a wheel be reinvented by fletcher_the_dog

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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others having a coffee break in the Monastery: (5)
    As of 2024-11-13 12:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      chatterbot is...






      Results (39 votes). Check out past polls.