in reply to How can I avoid creating two instances of the same object

If you are absolutely sure that the two packages will not clash using the same instance of $dbh, you can do something similar to:
package MyDbConnection; use DBI; #... our $dbh; sub get_dbh { unless $dbh { #real connection here } return $dbh; }
...and the User and Company packages should call MyDbConnection::get_dbh()

Replies are listed 'Best First'.
Re^2: How can I avoid creating two instances of the same object
by Anonymous Monk on Mar 02, 2006 at 15:21 UTC
    The problem isn't that I don't want have multiple dbh's out there. There are several ways to avoid this. I just don't want to have 30 lines of code that says Company->new, User->new, Address->new. How can I avoid having to call new for each package?