Ing. Branislav Gerzo wrote:
Bob Showalter [BS], on Friday, February 11, 2005 at 08:07 (-0500)
typed the following:

BS> Well, Bar.pm can't see the my() variable in your main program, so you need
BS> to:

BS> a) pass $dbh to db_get(), or

ok, this seems good for me, I call all db_operations with reference of
hash, so I can: $roh->{dbh} = $dbh, and after call db_get($roh), right
?

Or just, $roh->{dbh} = $dbh; and then in $roh: $roh->{dbh}

BS> b) set up some kind of variable in Bar.pm to hold the db handle and either

how ?

BS> set it directly ($Bar::dbh = $dbh),

hm, this looks ugly :)

But $roh->{dbh} = $dbh, and after call db_get($roh) does not?

Its one line in your script setting a fully namedvar, if thats ugly how are you ever going to use any variables :)

BS> or pass it to some routine (Bar->set_handle($dbh)), or

this is better I guess, how look example of this in Bar.pm ?

sub set_handle { $Bar::dbh = shift }

BS> c) Have $dbh live in Bar.pm and use Exporter to export it back to the main
BS> program, or

I want set $dbh in main script.

my $dbh = DBI->Connect(....

$Bar::dbh = $dbh;
$Baz::dbh = $dbh;

In 3 lines you just connected to the DB and given to two other packages.

Simple, no muss no fuss :)

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to