in reply to mod_perl with Apache::Registry with CGI.pm design considerations
Allow me to pick some relevant bits out of your posted code and paraphrase perrin's response:
my ($dbuser, $dbpass, $dbh); $dbuser = 'nobody'; $dbpass = 'NobodyPassword'; ... &middle_of_page(); # main content, DBI results, etc. ... sub middle_of_page { # ... $dbh = DBI->connect('DBI:whatever', $dbuser, $dbpass, {RaiseError = +> 1}); # prepare, execute and print query results # wrapped in HTML elements }
Congratulations! By referencing the global "$dbh and friends" within your middle_of_page sub, you have just created a closure!
Change to
... &middle_of_page($dbh, $dbuser, $dbpass); # main content, DBI resul +ts, etc. ... sub middle_of_page { my ($dbh, $dbuser, $dbpass) = @_; # ... $dbh = DBI->connect('DBI:whatever', $dbuser, $dbpass, {RaiseError = +> 1}); # prepare, execute and print query results # wrapped in HTML elements }
and that closure will not be created, thus preventing $dbh from being preserved across calls.
|
---|