I found a better solution now by making the walktree code clearer to myself (many thanks go to Frank, my local Perl guru :))
package WalkTree; use strict; my $DIRSEP = $^O =~ /Mac/ ? ':' : $^O =~ /Win|OS-2|DOS/ ? '\\' : '/'; my $MACOS = ( $^O =~ /Mac/ ) || 0; my $WINOS = ( $^O =~ /Win|OS-2|DOS/ ) || 0; sub walktree { my ( $dir, $filefunc, $dirfunc, $prune ) = @_; my @values; $MACOS and $dir =~ s/:$//; if ( -d $dir ) { if( $prune and $dir =~ /$prune/o ) { return undef } ref $dirfunc and $dirfunc->( $dir ); local *DH; opendir DH, $dir or warn "opendir '$dir' failed\n$!"; my $entry; while ( defined( $entry = readdir DH )) { !$MACOS and next if( $entry eq '.' or $entry eq '..' ); $MACOS and next if( $entry eq "Icon\n" ); my $fullpath = "$dir$DIRSEP$entry"; if( -d $fullpath ) { walktree( $fullpath, $filefunc, $dirfunc, $prune ); } elsif( -f $fullpath ) { ref $filefunc and $filefunc->( $fullpath ); } push @values, $fullpath; } closedir DH; } else { warn "$PACKAGE::walktree() - need a directory argument\n"; } return @values; } 1;
This way I can achieve what I wanted - creating objects on the fly while walktree is doing its job.
my $filefunc = sub { if( $filter ) { $_[0] =~ /$filter/o and push @files, File->new( name => $_[0] +) } else { push @files, File->new( name => $_[0] ) } }; WalkTree::walktree( $dir, $filefunc, sub { push @dirs , File->new( name => $_[0] ) }, $prune );
A different question now is whether a different design would be easier to maintain.

I found Randal Schwartz Linux Mag column using tie() in TieFinder very appealing. He manages to get results in the moment of a successful match.

Perhaps I should post the final result into the "Craft" categorie. It is most helpful on Macs where you can't do searching with pattern matching on filenames otherwise.

Thanks to everybody following my chaotic ideas.

In reply to Re: coderefs, walktree, OO by axelrose
in thread coderefs, walktree, OO by axelrose

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.