in reply to Sub in a Sub & Recursion
This is some ... interesting code. You may want to consider using consistent naming conventions as well as more intuitive return types.
In your first example, you're sharing a single variable within the scope of Get_Saves, @files. In the second example you're set up to use multiple copies since you're returning @files and assigning it to another @files variable as the result of the call to find. But at the same time you're trying to pass a reference to the @files in the scope of Get_Saves. These two mechanisms are in conflict.
One version:
sub Get_Saves { my @files; @files=find(\&FileName,"/usr/local/apache/htdocs/service/"); #sure + you want to hard code this? return \@files, $#files+1; # why return the size? }##END Get_Saves sub FileName { my @files; unless (($_ eq "." )or ($_ eq "temp.svd")){ # do you need to test +for '..' too? push @files, $_; } return @files; }##END FileName
Another version:
our @files; # globally accessible sub Get_Saves { @files=find (\&FileName,"/usr/local/apache/htdocs/service/"); return \@files, $#files+1; }##END Get_Saves sub FileName { unless (($_ eq "." )or ($_ eq "temp.svd")){ push @files, $_; } }##END FileName
I don't believe that find (\&FileName(\@files)) will work because you're passing a reference to the subroutine, not invoking it.
|
|---|