Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to use the processing function to push values to an array and return it once the whole directory is traversed. something like this:
use File::Find; @crap = (); finddepth (\(&wanted(\@crap)), $TMPDIR); print "crap is: @\n"; sub wanted { $in = $_[0]; push @$in, "dude"; }
I can pass in values to wanted and mess with them, but I can't get anything out. Any ideas?

Replies are listed 'Best First'.
Re: Returning values from File::Find processing function
by merlyn (Sage) on Feb 16, 2001 at 21:21 UTC
    You can't pass anything to the callback subroutine. You have to do it out of band:
    my @goods = (); use File::Find; find sub { push @goods, $File::Find::name if i_like_this($File::Find::name); }, @dirs; ...