in reply to coderefs, walktree, OO

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.

Replies are listed 'Best First'.
Re: Re: coderefs, walktree, OO
by Anonymous Monk on Jan 21, 2002 at 01:38 UTC
    Thanks for the correction. This points me into the right direction, checking conventions of dirfunc() return values.
    I'm having problems though to get it to work when $filter is applied.
      Sorry I completely ignored the $filter code segment, but it appears the $filter is going to suffer from the same fate as the previously discussed code did. The variables need to be passed in and better contained to avoid problems.
      That said, if this is a simple one time utility script, you can get away with the globals, but it is a dangerous practice.