Ing. Branislav Gerzo wrote:
> Hi,
>
> I have script:
>
> use strict;
> use warnings;
> use lib '/data/home/2ge/perl/modules';
> use Foo::Bar;
>
> my $dbh =
>
> DBI->connect("DBI:mysql:database=foo;host=localhost;port=3306", "",
> "") or die "Can't connect: ", $DBI::errstr; ...
>
> now I want to share this $dbh connection to Bar.pm, so I should use
> there:
> sub db_get {
> my ($a) = $dbh->selectrow_array("SELECT foo FROM bar WHERE foo =
> ?", {}, shift );
> }
Well, Bar.pm can't see the my() variable in your main program, so you need
to:
a) pass $dbh to db_get(), or
b) set up some kind of variable in Bar.pm to hold the db handle and either
set it directly ($Bar::dbh = $dbh), or pass it to some routine
(Bar->set_handle($dbh)), or
c) Have $dbh live in Bar.pm and use Exporter to export it back to the main
program, or
(lots of other ways...)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>