in reply to Global or not global
Historically, I have dealt with the problem of “global DB handles” and other such things simply by defining a package named Global. This package contains functions which produce the necessary values, if necessary doing so on-demand. For example, my $dbh = Global::DBHandle;. (If you need to use more than one database, simply have a separate function to automagically produce each handle.) You can replace this functionality with stuff to, say, use a DB handle cache, without affecting anything else in the program. And that is what I consider to be a win: there is a globally-available yet concretely documented way to obtain the necessary values and handles, and each is a function that returns it. If anything “has to happen,” here is a central and obvious place to put that. It is crystal-clear what is being done and why. This has for a long time been my standard practice.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Global or not global
by xtpu2 (Acolyte) on Feb 18, 2014 at 10:07 UTC |