Subliminal Kid has asked for the wisdom of the Perl Monks concerning the following question:
Someone said to use Closure Vars and I read "Subroutine References and Closures" from Advanced Perl Programming but I'm not getting it. HELP Cheers, Jamesuse File::Find; find(\&wanted, shift(@ARGV)); # I would like the @dirlist here # but I can't get it returned for the life of me. exit; sub wanted { return unless -d $_; my @dirlist; push(@dirlist,$File::Find::name); return(@dirlist); }
and I want to do it without the global my @dirlist at the top.use strict; use File::Find; sub main; my @dirlist; main(); exit; sub main { findit(); dostuff($_) for @dirlist; } sub findit { find(\&wanted, shift(@ARGV)); } sub wanted { return unless -d $_; push(@dirlist,$File::Find::name); } sub dostuff { print "$_\n" }
|
|---|