On Fri, 24 Jan 2003 10:22:35 -0000 Steve Haslam <[EMAIL PROTECTED]> wrote:

> >i ask myself what will happen if a script will die befor i do a
> >disconnect... will this connection stay alive and will never close?
> 
> The connection will be closed. It might be closed gracefully if Perl
> destroys objects in the right order. If nothing else, your socket
> connection
> will be closed by the operating system when your script's process
> terminates. It is advisable to run ->disconnect if possible, but not
> mandatory. Remember you can write sth like:
> 
> $SIG{__DIE__} = sub { eval { $dbh->disconnect }; die $_[0]; }
> 
> to act as a kind of on-error-unwind mechanism.

You don't need anything as fancy as that.  An END block would have
a similar effect.  Set $dbh = undef when you disconnect in the main
code so the if clause works correctly.

END {
   local $?;
   eval { $dbh -> disconnect if $dbh; }
}

-- 
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.

Reply via email to