Don't ask to ask, just ask | |
PerlMonks |
Re: Defining a sub within a sub: OK?by moritz (Cardinal) |
on Oct 14, 2009 at 22:40 UTC ( [id://801229]=note: print w/replies, xml ) | Need Help?? |
As others have pointed out already there's no sub inside a sub in your code. I'll answer the question asked in your title though: I consider it a bad idea to define a named sub within another sub. It's visible from the outside still, but obeys rather unintuitive scoping rules:
There's no sane way in which perl could handle a call to b() from the outside. However there's nothing wrong with defining an anonymous subroutine inside another sub. Actually it's quite common, and used very often in functional programming.
Perl 6 - links to (nearly) everything that is Perl 6.
In Section
Seekers of Perl Wisdom
|
|