Don't use BEGIN or END as subroutine names since they have special meaning
in Perl. BEGIN blocks are executed at compile time while END blocks are
always executed at program termination (unless a kill signal or something
similar is sent by the OS). Try using a different name for your
subroutines... it might have something to do with that since I can't see
anything glaring at me from the code snippet you have (of course it's 7a
and I'm not thinking very clearly yet).
--Curt
On Tue, 10 Apr 2001, [iso-8859-1] Tom Robinson wrote:
> Hi,
>
> I'm trying to use the DBI within a package I'm
> writing, and am getting an odd error (warning). What
> is even more odd is that everything actually works
> fine.
>
> Here is what I am doing in the package:
>
>
> package Package;
>
> # class data
>
> my $Dbh;
>
> sub BEGIN {
> $Dbh = DBI->connect("DBI:mysql:database=mydb",
> {PrintError => 1, RaiseError
> => 0})
> or croak "Cannot connect to mysql database:
> $DBI::errstr\n";
>
> }
>
> ....
>
> sub END {
> $Dbh->disconnect()
> or croak "could not disconnect from database:
> $DBI::errstr";
> }
>
> In between I run a routine which just dumps a list of
> tables in the database, so my script looks something
> like:
>
> use Package;
> Package->dumptables();
>
> And I get a printout of the tables, which means it
> must be connecting ok. I don't get the croak message
> on the $Dbh->disconnect(), so that must also be
> working. But I am getting:
>
> Useless use of private variable in void context at
> Package.pm line 56.
>
> line 56 being the one that just contains:
>
> $Dbh->disconnect()
>
> so it must be saying $Dbh is being used in a void
> context. But if that were the case, surely the
> disconnect method call would fail with cannot call
> method on undefined object?
>
> Any help appreciated.
>
> Tom
>
>
> ____________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
> or your free @yahoo.ie address at http://mail.yahoo.ie
>