in reply to passing DBI database handles to subroutines

Moo, in theory your function should work. Is this the actual code you are using? Without seeing more code and the error message you are getting, I can but guess.

My main thought is that the

my $dbh = DBI->connect( " yada yada " ), { PrintError => 0}, or die "cannot open db connection: $DBI::errstr\n";
is occuring in a different scope than the return call is. For example, if you are doing something like:
eval { my $dbh = DBI->connect( " yada yada " ), { PrintError => 0}, or die "cannot open db connection: $DBI::errstr\n"; } return $dbh;
$dbh has gone out of scope before being returned and you will get undef on the other side.

Try using something like

sub db_connection { my ( $self ) = @_; my $dbh;

Standard statements of making sure you are using -w and strict and a request to use the <code></code> tags.

mikfire

Replies are listed 'Best First'.
RE: Re: passing DBI database handles to subroutines
by moo (Acolyte) on Aug 10, 2000 at 23:57 UTC
    Thanks everyone for your replies. I am currently experimenting with your suggestions to see which one works best. Any code that works gets stuck in the TIMTOWTDI drawer. I tried Merlyn's suggestion first and it works great. I am also messing around with other people's suggestions and they work too.... I spent several hours researching your responses. I will try to post a "here is what I learned" summary for any monks new to DBI. Thanks, moo