Gangabass has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: $@ alternative
by kyle (Abbot) on Sep 10, 2007 at 12:14 UTC | |
by ikegami (Patriarch) on Sep 10, 2007 at 12:44 UTC | |
Re: $@ alternative
by runrig (Abbot) on Sep 10, 2007 at 05:33 UTC | |
by Gangabass (Vicar) on Sep 10, 2007 at 06:35 UTC | |
by sgt (Deacon) on Sep 10, 2007 at 08:30 UTC | |
Re: $@ alternative
by samtregar (Abbot) on Sep 10, 2007 at 21:46 UTC | |
by Gangabass (Vicar) on Sep 11, 2007 at 06:06 UTC | |
Re: $@ alternative
by rdfield (Priest) on Sep 10, 2007 at 11:47 UTC |
Back to
Seekers of Perl Wisdom