I accidently wrote the below code which embeds a subroutine inside a subroutine. To my surprise it worked fine. It had't even occurred to me that this would be legal code and I could think of no reason to do it.
Ok I thought that's interesting but it must be in some way bad and I want it to look more normal so I'll remove the embedded sub. But whenever I seperate the below into 2 subs @files is out of scope in sub FileName. So I need a way to pass @Files to sub FileName. Sub FileName is being called recursively by find, I tried find (\&FileName(\@files),"/usr/local/apache/htdocs/service/"); but got a is not code ref error.
I've never been much good at recursion so some advise would be appreciateduse File::Find; sub Get_Saves { my @files; sub FileName { unless (($_ eq "." )or ($_ eq "temp.svd")){ push @files, $_; } }##END FileName find (\&FileName,"/usr/local/apache/htdocs/service/"); return \@files, $#files+1; }##END Get_Saves
sub Get_Saves { my @files; @files=find (\&FileName(/@files),"/usr/local/apache/htdocs/service +/"); return \@files, $#files+1; }##END Get_Saves sub FileName { unless (($_ eq "." )or ($_ eq "temp.svd")){ push @files, $_; } return @files; }##END FileName
In reply to Sub in a Sub & Recursion by hakkr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |