in reply to Are global variables "bad"?
What you're looking for is called a "singleton" - an object which naturally has a single instantiation which is shared by everyone that needs it. This is common for DBI handles for example. You might take a look at Class::Singleton for a tiny bit of implementation help but personally I'd just code the interface myself.
As to whether it's "bad" - no, but it does come with some danger. In the case of DBI handles the fact that they're often shared by disparate modules can make agreeing on DBI options hard - one part needs a particular RootClass, another requires RaiseError to be off, etc. It can cause "action at a distance" problems too.
-sam
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Are global variables "bad"?
by doom (Deacon) on Apr 21, 2009 at 22:57 UTC | |
by samtregar (Abbot) on Apr 22, 2009 at 17:27 UTC | |
Re^2: Are global variables "bad"?
by eric256 (Parson) on Apr 21, 2009 at 18:40 UTC | |
by gwadej (Chaplain) on Apr 21, 2009 at 18:56 UTC | |
Re^2: Are global variables "bad"?
by jpearl (Scribe) on Apr 21, 2009 at 17:14 UTC | |
by DStaal (Chaplain) on Apr 21, 2009 at 17:32 UTC | |
by Porculus (Hermit) on Apr 21, 2009 at 19:38 UTC | |
by ELISHEVA (Prior) on Apr 22, 2009 at 03:26 UTC |
In Section
Seekers of Perl Wisdom