Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: sub scope question

by papidave (Monk)
on Feb 07, 2008 at 17:36 UTC ( #666825=note: print w/ replies, xml ) Need Help??


in reply to Re^3: sub scope question
in thread sub scope question

ikegami,

Thank you for the comments on my implementation details; I have improved my wording above. As regards the remainder of your response, I think we both agree that nesting named functions has no benefit in Perl; we differ only in how to resolve it.

By going with an unnamed function assigned to a local var, you eliminate the "named" part; by moving $list_ref outside the function, you can then also move the named function to main scope, thereby eliminating the "nesting".

In either case, I favor passing arguments into a subroutine over retention of state information in a closure or any kind of shared variable, because I find it easier to maintain -- but then, TMTOWTDI.


Comment on Re^4: sub scope question
Select or Download Code
Re^5: sub scope question
by ikegami (Pope) on Feb 07, 2008 at 18:40 UTC

    Making a local variable variable into a semi-global one in order to use it to pass arguments to a function doesn't sound like the right approach to me. For starters, it breaks if the outer function is re-entrant and can break if the inner function is re-entrant, and that's when I normally use nested subs.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://666825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-12-26 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls