Well I think I found the problem. In the walktree code,
it is passing a directory name and an array into your the
dirfunc callback. The callback that is in the current
code doesn't account for the incoming list so previous
values are removed.
The workaround code works because it using a strange and
dangerous scoping of @files. That is the @files is defined
prior to the sub so it is in scope when the sub is created
and the values are added to it inside of the $dirfunc callback
in walktree, but since its scope is not limited to the $dirfunc
callback it could cause problems in the future. So I rewrote
the callback to this:
### THIS RETURNS ONLY A SINGLE DIRECTORY, no object reference !???
undef @files;
$dirfunc = sub {
return undef unless $_[0]; # Mac specific
my ($dir,@val) = @_;
if( $filter ) {
$dir =~ /$filter/o and FileFinder->new( name => $dir )
}
else {
push @val, FileFinder->new( name => $dir );
return @val;
}
};
This is only slightly different from the workaround that you present,
but it avoids the issues with possible variable scoping issues I think.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.