in reply to Re^2: OO question
in thread OO question
but i think the second call to MyDB->dbh is independent to the first one and like a new instance of something.
New instance of what? $DBH? no.
{ package Cow; my $i; sub moo { print(("moo " x ++$i), "\n"); } } Cow->moo(); # moo Cow->moo(); # moo moo Cow->moo(); # moo moo moo
{ package MyDB; my $DBH; sub dbh { if ($DBH) { print "found existing $DBH\n"; } else { $DBH = 'dbh'; print "Init $DBH\n"; } } } MyDB->dbh(); # Init dbh MyDB->dbh(); # Found existing dbh MyDB->dbh(); # Found existing dbh
|
|---|