Customer ask me to write DBI script which will change server if current server did't response. I write this simple code:
my $timeout = 10; #10 seconds timeout foreach my $source (@sources) { my dbh = connect_to_db($source); my sth = $dbh->prepare(YOU_QUERY_GOES_HERE); eval { local $SIG{ALRM} = sub {die "alarmn";}; alarm($timeout); $sth->execute(YOUR_PARAMS); alarm(0); }; unless ($@) { last; #ALL OK } else { #didnt print "Timeout happens!n"; } }
But customer said that he already use $@ in your script (and he can use it only once) so i need to rewrite my sample without using $@. How i can do this? May be there is some way to declare local copy of $@ and after my block to restore original value?
In reply to $@ alternative by Gangabass
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |