Re: Problem using DBI in Object Oriented Package
Hi, When I comment out that line, the error disappears. --- Ronald J Kimball <[EMAIL PROTECTED]> wrote: > On Tue, Apr 10, 2001 at 12:26:39PM +0100, Tom > Robinson wrote: > > > 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. > > > sub END { > > $Dbh->disconnect() > > or croak "could not disconnect from > database: > > $DBI::errstr"; > > } > > > 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? > > I suspect that the error is actually on another > line. > > $Dbh on that line is not in a void context, because > it is on the left-hand > side of a method call. > > Ronald 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
Re: Problem using DBI in Object Oriented Package
On Tue, Apr 10, 2001 at 12:26:39PM +0100, Tom Robinson wrote: > 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. > sub END { > $Dbh->disconnect() > or croak "could not disconnect from database: > $DBI::errstr"; > } > 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? I suspect that the error is actually on another line. $Dbh on that line is not in a void context, because it is on the left-hand side of a method call. Ronald
Re: Problem using DBI in Object Oriented Package
Hi, Yeah I know about the special meanings of BEGIN and END, which is exactly why I'm using them, to connect to the db as soon as possible and then disconnect as the last thing. --- Curt Russell Crandall <[EMAIL PROTECTED]> wrote: > 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 > > > 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
Re: Problem using DBI in Object Oriented Package
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 >
Problem using DBI in Object Oriented Package
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