punkish has asked for the wisdom of the Perl Monks concerning the following question:
I read Defining a sub within a sub: OK? with interest, but consider the following
sub foo { my @arra = ('a' .. 'z'); my @arrb; for ( 0 .. ( $#arra - 1) ) { bar($_); } bar($#arra); sub bar { my ($i) = @_; push @arrb, $arra[$i]; } return \@arrb; }
The above works, but what all sentiments and principles am I violating here? (besides, of course, Blond highlights with a hint of purple are just "so 2007
Essentially, bar() will never be called from outside foo(), and makes sense only within the context of foo(). In case I shouldn't be doing the above, then how should I rewrite it?
--
when small people start casting long shadows, it is time to go to bed
when small people start casting long shadows, it is time to go to bed
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: a sub within a sub -- revisiting
by ikegami (Patriarch) on Apr 10, 2010 at 04:54 UTC | |
by PeterPeiGuo (Hermit) on Apr 10, 2010 at 05:56 UTC | |
Re: a sub within a sub -- revisiting
by Anonymous Monk on Apr 10, 2010 at 04:14 UTC | |
by ikegami (Patriarch) on Apr 11, 2010 at 06:21 UTC | |
Re: a sub within a sub -- revisiting
by PeterPeiGuo (Hermit) on Apr 10, 2010 at 05:29 UTC | |
|
Back to
Seekers of Perl Wisdom