Perl Monk, Perl Meditation | |
PerlMonks |
Re: Scope of subroutines with same nameby Joost (Canon) |
on Feb 05, 2009 at 23:42 UTC ( [id://741744]=note: print w/replies, xml ) | Need Help?? |
Two things are going on here:
1. named subroutines have package scope. it doesn't matter if you declare them inside braces, or another sub, there will always be just one sub with any given name in a single package. anonymous subs don't have this restriction, since they don't have names. 2. subroutines are normally compiled before execution of anything else. Combined, these two rules mean that the last subroutine (which is the bottom one in this example) is the one that's active when myfunction_one is called. In general, it also means declaring nested named subroutines is only going to be confusing. This is one of the areas where perl just isn't as consistent as we'd like it to be, but since it's not clear what the really good solution is, and it's fairly easy to work around the problems it causes, don't expect this to be "solved" in perl 5.
In Section
Seekers of Perl Wisdom
|
|