in reply to Re: Re: Using objects in exported functions
in thread Using objects in exported functions
You only have three options: pass it around, store it in objects that need it, or make it globally accessible. You can do the latter with a bit of encapsulation though:
my $dbh = DBI->connect($db_info, 'username', 'password', { PrintError => 0 } ) or die("Couldn't connect to database\n"); sub get_handle { my $dbh; } print "info: " , getdb() , "\n";
Then you can call main::get_handle() from anywhere, instead of accessing a global variable. It's effectively the same, though it's a little nicer with the encapsulation.
|
|---|