LPM: a problem with modularity using Net::LDAP

David Hempy hempy at ket.org
Mon Nov 6 08:47:48 CST 2000


>On Thu, Oct 26, 2000 at 02:37:33PM -0400, Joe Hourcle wrote:
> >
> > I'm attempting to make a module which essentially returns an object from a
> > different module.
> >


I'm doing something similar in my pressroom.  There are several programs 
that all use pressroom.pm, which includes:

pressroom.pm snippet:
>use DBI;
>
>         ## returns a $db handle to the pressroom, or dies with a message.
>sub pressroomOpenDB {
>         my $DSN = "pressroom";
>
>         my $dbh = DBI->connect("DBI:ODBC:$DSN", '', '', {AutoCommit => 0, 
> PrintError=>1, RaiseError => 0});
>
>         unless ($dbh) {
>             die "Error connecting to $DSN $!\n";
>          }
>         return $dbh;
>}


Then my calling programs have something like:

scout.pl snippet:
>use DBI;
>use pressroom;          #page footers and other common subs.
>
>my $dbh = pressroomOpenDB();
>
>my $image_insert_sth = $dbh->prepare('insert into image (
>         imageid, sourceext, releaseid, cutline, usage, imgapr, imgaprby
>         ) values (?, ?, ?, ?, ?, ?, ?) ')
>                 or die "Cannot prepare insert image.  $!";




Only now that I read this email, I'm wondering how this works at all.  (It 
does work, btw.)  Seems like pressroomOpenDB's $dbh would go out of scope 
at the end of the sub.  Maybe it is, and I'm just luckily getting away with 
it?  Or does perl automagically realize that I'm still using that value and 
doing what I mean, not what I say?

Hrmm...I thought I was going to be offering a solution, but I'm ending up 
more confused than I started.  Anybody care to set me straight?  Is my code 
a ticking time bomb?


-dave  :-|



-- 
David Hempy
Internet Database Administrator
Kentucky Educational Television
<hempy at ket.org> -- (859)258-7164 -- (800)333-9764





More information about the Lexington-pm mailing list