|laziness, impatience, and hubris|
Global variable vs passing variable from sub to subby kiat (Vicar)
|on Sep 13, 2004 at 16:06 UTC||Need Help??|
kiat has asked for the
wisdom of the Perl Monks concerning the following question:
I would like to seek your views on the merits/demerits of
(1) declaring a shared variable as global versus
(2) passing a localised variable from one subroutine to the next one that requires its value.
With (1), the variable is declared at the top level. Somewhere in the code, it gets assigned a value and that value is used by other subroutines.
With option (2), a localised variable is declared from within a subroutine. This variable is passed from this subroutine to the next one and to the ones after that which use that value.
I look forward to reading your views :)
Thanks in anticipation.