tiaxajeff has asked for the wisdom of the Perl Monks concerning the following question:
The question: Am I setting myself up for any weird side effects by potentially confusing the reference counter, or am I safe?# a subroutine returns a ref to a database handle... my $pdb = &openDatabase(); # the ref to the db handle is passed to a subroutine as an # optional hash element... &doSomething(DB=>$pdb,FOO=>'bar'); # the subroutine assigns the ref to a scalar if it was # passed, or directly obtains one of its own if it wasn't, # does its thing, then closes the db handle if # it opened it... sub doSomething { my(%param)=@_; # we assign the ref to $rdb if it's defined, or open the # database for the first time if it's not my ($rdb) = ((defined($param{'DB'})) && ($param{'DB'})) ? $param{'DB +'} : &openDatabase(); # the subroutine does something useful... $$rdb->disconnect if(!(defined($param{'DB'}))); return('done'); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: lifetime of refs to DBI handles passed to sub as hash elements and assigned to scalar within it
by dragonchild (Archbishop) on Aug 30, 2001 at 22:18 UTC | |
|
Re: lifetime of refs to DBI handles passed to sub as hash elements and assigned to scalar within it
by VSarkiss (Monsignor) on Aug 30, 2001 at 22:44 UTC | |
by tilly (Archbishop) on Aug 31, 2001 at 01:00 UTC | |
|
Re: lifetime of refs to DBI handles passed to sub as hash elements and assigned to scalar within it
by runrig (Abbot) on Aug 30, 2001 at 22:29 UTC |