hakkr has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sub in a Sub & Recursion
by djantzen (Priest) on Jan 21, 2002 at 17:40 UTC | |
|
Re: Sub in a Sub & Recursion
by demerphq (Chancellor) on Jan 21, 2002 at 18:20 UTC | |
|
Re: Sub in a Sub & Recursion
by goldclaw (Scribe) on Jan 21, 2002 at 19:29 UTC | |
|
Re: Sub in a Sub & Recursion
by derby (Abbot) on Jan 21, 2002 at 19:55 UTC | |
by hakkr (Chaplain) on Jan 21, 2002 at 20:19 UTC | |
by dmmiller2k (Chaplain) on Jan 22, 2002 at 08:43 UTC | |
|
Re: Sub in a Sub & Recursion
by little (Curate) on Jan 21, 2002 at 16:42 UTC | |
|
Re: Sub in a Sub & Recursion
by Anonymous Monk on Jan 21, 2002 at 22:45 UTC |