Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Qualified package variable access

by tobyink (Canon)
on Dec 17, 2020 at 22:03 UTC ( #11125372=note: print w/replies, xml ) Need Help??


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 ); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11125372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-10-27 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (93 votes). Check out past polls.

    Notices?