in reply to Graceful handling of DBI connect errors'

I generally wrap all DBI-related procedures in eval blocks. This includes statement prepares & executes. Here's an example for DBI connections:
my $dbh; eval { $dbh = DBI->connect($dsn, $stuff, { RaiseError => 1 }); # will die if it doesn't work } if ($@) { # you can process the error string in $@ and clean it up # for output print $error; }
Of course, if you connect to the DB with RaiseError set, you will have to wrap all DB-related methods in eval blocks to avoid die'ing.

Also, your code has if (undef $dbh) to check for connection errors. Yikes! This will set the value of $dbh to undef each time, and will always return undef, so the top part of your if-statement will never be executed, only the else-block. This may be why you're having problems. You probably meant to say if (not defined $dbh).

blokhead