Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by merlyn (Sage)
on Sep 13, 2004 at 16:24 UTC ( #390594=note: print w/replies, xml ) Need Help??


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

Both of them are bad. Both "passing around" and "global variables" are a signs of a misdesign.

If you have a value that must be shared, make it a "regional" variable, accessible to a few subroutines that deal with it, and in turn provide a higher-level interface that don't need to expose that variable. For example, if you're talking about something like a database handle, create a module that does all the DB stuff, and then you can initialize (perhaps lazily) the database handle there. Thus, the rest of the program does not have access to the database handle, but you still don't have to pass it around a lot.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • 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:35 UTC
    Thanks, merlyn!

    Hm...I'm not quite sure if what I'm currently labelling as "global" is in fact "regional" in my implemenation. The "global" I mentioned in the parent node is used in a module and is shared by a couple of subroutines. If I understand you correctly, that's okay right?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://390594]
help
Chatterbox?
[marto]: clever stuff
[Corion]: marto: Thanks for pointing me to Tinc - I found at least some article that suggests that what I want would be possible with Tinc. Now I can try that out :)
[marto]: I think you can do what you want without too much hassle, but yeah, please try and let me know if it works well :)
[marto]: sadly I've still not remembered the name of that x86 all in one we discussed
[Corion]: marto: Heh - I looked at the Intel things and they were all at EUR 80 or upwards, and that's a bit too much (or rather, for that money, I'd look for a NAS already)
[marto]: click bait marketing is making it harder to find stuff I can't remember based upon a few terms :(

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2018-01-17 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (201 votes). Check out past polls.

    Notices?