Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help on DBI handles

0 views
Skip to first unread message

Mohammed Amduka

unread,
May 22, 1996, 3:00:00 AM5/22/96
to

How do I pass a handles to subroutines in my program? I tried
global and by refernce. What I want to do is after connecting to
a database, I want to pass the handle to a subroutines that use the
handle to retrive or insert records. In oraperl I used to pass
parameters by refrence without problem.

Here is what i tried and failed,

in the main module ..

$dbh = DBI->connect(...)

&foo(\$dbh)

.
in the sub
sub foo {
$dbref = @_;

$stmt = 'some query'
$$dbref->prepare($stmt);

}


I appreciate your help.

Mo

Tim Bunce

unread,
May 23, 1996, 3:00:00 AM5/23/96
to

In article <31A321...@bgl.psycha.upenn.edu>,

Mohammed Amduka <moha...@bgl.psycha.upenn.edu> wrote:
> How do I pass a handles to subroutines in my program? I tried
> global and by refernce. What I want to do is after connecting to
> a database, I want to pass the handle to a subroutines that use the
> handle to retrive or insert records. In oraperl I used to pass
> parameters by refrence without problem.
>
> Here is what i tried and failed,
>
> in the main module ..
>
> $dbh = DBI->connect(...)
> &foo(\$dbh)
>
> sub foo {
> $dbref = @_;
> $stmt = 'some query'
> $$dbref->prepare($stmt);
> }

You're trying far too hard. Reread perlref etc.

$dbh = DBI->connect(...)
foo($dbh);

sub foo {
my($dbref) = @_;
$dbref->prepare(...);
}

Note that "$dbref = @_" will not do anything useful. Reread the
perl manuals about list and scalar contexts.

Tim.

0 new messages