in reply to CGI and require

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

Replies are listed 'Best First'.
Re: Re: CGI and require
by snorks (Initiate) on May 30, 2004 at 10:16 UTC
    Thanks to everyone. I've created the module and everything looks good