good chemistry is complicated,
and a little bit messy -LW
Avoiding global object handleby Biker (Priest)
|on Mar 26, 2002 at 09:44 UTC||Need Help??|
Biker has asked for the
wisdom of the Perl Monks concerning the following question:
So, I do create numerous inhouse business specific Perl modules. (I.e. not CPAN candidates, too specific for that.)
Now the question is how to store this handle. The handle will be used between many, the majority, of the subs in the application. But not all subs will need this object handle.
I see two classical ways of handling the handle. (No pun intended.)
The second solution means putting the handle on the call stack for almost all subs. Performance hit? Maybe, since these are apps that do a lot. And I mean a lot.
It will also imply that a number of subs will take the handle as a parameter with the only objective to provide it to another sub, called from this sub. Not very clean at all.
I came up with the following approach:
Now, the result from this is that I have just hidden a global variable inside a sub. I have created a sub to get to my global object handle.
I don't use vars. I don't have a global variable in it's traditional meaning. Technically, my global variable is implemented as a function call.
All subs are available throughout the application eq 'good approach'.
No global variables are available throughout the application eq 'good approach'.
Everything went worng, just as foreseen.