Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Global variable vs passing variable from sub to sub

by kiat (Vicar)
on Sep 14, 2004 at 11:16 UTC ( #390795=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Global variable vs passing variable from sub to sub
in thread Global variable vs passing variable from sub to sub

Hi BUU,

Let me put it this way and see if it makes more sense. I have a 11,000 line program. It has 10 globals at the top. Because they're global, this means that *any* single one of those 11,000 lines can modify that global value. Therefor, when your global has the *wrong* value, you have problems finding it, because you must examine 11,000 lines of code. Using properly scoped lexicals, you might have a function that is only 10 lines long with a lexical declared at the top. Now you know only 10 lines total can affect that variable, thus vastly reducing the search space.
I think this is an extreme case where globals are used all over the place. Maybe they are cases like that.

I once had the unfortunate task of tweaking someone's script where not only were the variables global, they were also not declared with my. It was unpleasant, to say the least.

However, I think there's some justification for selective use of what meryln termed "regional" globals - globals used within a module (if I understood him correctly).


Comment on Re^3: Global variable vs passing variable from sub to sub

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-07-28 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (191 votes), past polls