my $alarm = 0; eval { local $SIG{ALRM} = sub { $alarm=1 }; alarm(3); $dbh = DBI->connect( "dbi:Oracle:$dbn", $usr, $pwd ,{ AutoCommit=>$self->auto_commit() ,RaiseError=>1 ,PrintError=>$self->print_err() } );
[You ought to alarm(0) inside the eval block as well, else there's a chance the alarm will be delivered between the eval and ending and the following alarm(0). That would be fatal.]
}; alarm(0); if ($@).... if ( $alarm ).... etc
The question that I have is, assuming:
my $alarm = 0; eval { local $SIG{ALRM} = sub { $alarm=1 }; alarm(3); $dbh = DBI->connect( ... ); alarm(0); }; alarm(0);
is there really a need to alarm(0) outside the eval? Basically, if the eval fails, doesn't the alarm(3) automatically get disabled due to it being in the eval block? I'm wrapping up my work on DBIx::HA, a high-availability module for DBI, and I want to make sure that this code is as tight as it can be.
And if we do need to have the alarm(0) both in and out of the eval block, are there any unforseen consequences to setting alarm(0) a couple of times in a row?
My assumption is that I should put both alarm(0), but I just want to make sure.
Thanks Henri.