in reply to Re: Qualified package variable access
in thread Qualified package variable access
Better yet:
package ECClib; my $dbh; sub get_dbh { $dbh ||= db_connect( $dbuser, $dbpasswd, $dbserver ); }
And:
use ECClib; { my $dbh = ECClib->get_dbh; ...; } { my $dbh = ECClib->get_dbh; # gets the same instance! ...; }
If you're using Perl 5.10+:
package ECClib; use v5.10; sub get_dbh { state $dbh = db_connect( $dbuser, $dbpasswd, $dbserver ); }
|
|---|