You really want a module rather than a require as it addresses the issues you are trying to solve. Simple Module Tutorial. For example then you could have a function like:
use vars '$dbh'; END{ $dbh->disconnect() if $dbh } sub connect { # connect database handle unless we have one already $dbh ||= DBI->connect.... }
Then in your code you just call connect() whenever and wherever you need a DBH. The first call to it $dbh will be undef so it will get initialized. After that the connect() function just returns the existing DBH. Bonus features include automatically disconnecting and only connecting if you have to.
cheers
tachyon
In reply to Re: CGI and require
by tachyon
in thread CGI and require
by snorks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |