[Melbourne-pm] DBI connect()'s, scope and disconnects

Gautam Gopalakrishnan thatha at gmail.com
Thu Jul 26 22:12:23 PDT 2007

> >foreach (@array) {
> >   #connect, and do stuff
> >}
> >continue {
> >   $dbh->disconnect() (if defined $dbh)
> >}
> Isn't $dbh already out of scope once the continue block is called?

$ perl -le 'while(my $x = <>) {print "1.$x"} continue{print "2.$x"}'
works like how I wanted it to.

$ perl -le 'while(<>) {my $x=$_; print "1.$x"} continue{print "2.$x"}'
does not and this is the case we're talking about. You can get around
it by declaring $dbh just before the loop, but not sure if that's

More information about the Melbourne-pm mailing list