in reply to Return values, Closure Vars from File::Find &wanted subs?

I don't think you get how the 'wanted' function works. It is run once for each file and directory in the tree you're searching.

If you don't want a global array to store these results, you have two choices: you can either make the wanted function do the work on each file, or you can change the structure of your program. The former might look like:

sub main { findit(); # dostuff($_) for @dirlist; } sub findit { find(\&wanted, shift(@ARGV)); } sub wanted { return unless -d $_; # push(@dirlist,$File::Find::name); dostuff($File::Find::name); } sub dostuff { print "$_\n" }

I commented out the lines in your code, so you can more easily see the change.

The latter solution might look something like this:

sub main { my @dirlist; find( sub { return unless -d $_; push(@dirlist,$File::Find::name); }, (shift @ARGV) ); dostuff($_) for @dirlist; } sub dostuff { print "$_\n"; }

I highly recommend the first approach -- it seems silly, in most cases, to build a list of files and then act on it when you can act on each file as you find it.

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law