On Mon, Mar 26, 2001 at 12:40:51PM -0500, Curt Russell Crandall wrote:
> This may be more of a general Perl question than a DBI one, but since DBI
> is involved, I thought I'd ask anyway.
> 
> I create a database handle called $dbh_sale.  I want to ensure that this
> handle is destroyed at the end of the program... so, I wrote up this chunk
> of code
> 
> END
>  {
>      $dbh_sale->disconnect();   ###this is line 155
>  }
> 
> When doing a perl -c using Perl 5.00404, I get:
> 
> test.pl syntax OK
> Can't call method "disconnect" without a package or object reference at
> test.pl line 155.
> END failed--cleanup aborted.
> 
> 
> However, I get no such error/warning when running under Perl 5.6.0.  Since
> I am forced to use Perl 5.00404, I am concerned that this error could
> cause a problem down the line.  Does anyone know why Perl 5.00404 is
> reporting this?  Since I've only used Perl 5.00503 and Perl 5.6.0, I've
> never run into this problem before and I have no idea if this a really a
> bug or if it's just sloppy error reporting by the old interpreter.
> 

Unfortunately, perl5.004_04 runs END {} blocks even when the -c switch is
used.  This misbehavior was corrected in later versions of Perl.

Here's an easy fix:

END {
    $dbh_sale->disconnect() if $dbh_sale;
}

Ronald

Reply via email to