Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Qualified package variable access

by tobyink (Canon)
on Dec 17, 2020 at 22:03 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (None)
    As of 2024-04-19 00:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found