in reply to Re: Re: Sub in a Sub & Recursion
in thread Sub in a Sub & Recursion
It seems to me, that if you want to use a closure for such a thing, you'll want to use an anonymous sub instead of your FileName sub. Then the @files array will be shared as you expect it to be (e.g., each time Get_Saves is called, $sub will be bound to the new instance of @files).
sub Get_Saves { my @files; my $sub = sub { unless (($_ eq "." )or ($_ eq "temp.svd")){ push @files, $_; } }; find ($sub,"/usr/local/apache/htdocs/service/"); return \@files, $#files+1; }
As to how to make two separate subs, derby seems to have already answered that. You'd "need to use either global @files or a lexical @files defined outside of Get_Saves and FileName".
Hope this helps
dmm
If you GIVE a man a fish you feed him for a day
|
|---|