Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Global variable vs passing variable from sub to sub

by dragonchild (Archbishop)
on Sep 13, 2004 at 16:15 UTC ( [id://390593]=note: print w/replies, xml ) Need Help??


in reply to Global variable vs passing variable from sub to sub

I seriously hope I don't have to describe to you the plethora of perils encountered when using global variables. Bugs are notoriously difficult to track down and the code generally devolves into a mess.

That said, selective usage of global variables can often be a big benefit to a program's maintainability. For example, most session implementations in web applications are glorified global variables. Using a sessionstore can significantly reduce the amount of tramp data that goes on the URL.

Often, specific variables are maintained globally, such as $dbh. With proper documentation, I don't see a problem with this. I would (and do) prefer using a singleton instead of an explicit global, just so that new usages can be easily added. But, styles differ.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

  • Comment on Re: Global variable vs passing variable from sub to sub

Replies are listed 'Best First'.
Re^2: Global variable vs passing variable from sub to sub
by kiat (Vicar) on Sep 13, 2004 at 16:45 UTC
    Thanks, dragonchild!

    I'm aware of the mess having lots of globals can create so I generally try to keep them to the minimal.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-20 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found