Re: general retry function
- From: cdevers@xxxxxxxxx (Chris Devers)
- Date: Tue, 27 Sep 2005 19:44:33 -0400 (EDT)
On Tue, 27 Sep 2005, Ing. Branislav Gerzo wrote:
> Could be anyone so nice and write it ?
I'm sure someone *could*, but I wouldn't count on it happening :-)
> I have some snippets here, using eval {} and catch errors with calling
> recursive sub, but I don't think thats the best option.
That's a reasonable line of thought.
Here's a similar approach:
my $tries = 0;
while ( $tries < 10 ) {
my $result = do_something_risky();
break if ( $result != 0 );
$tries++;
if ( $tries == 10 ) {
die "Couldn't do the risky thing after 10 tries, sorry. $!"
}
}
sub do_something_risky {
...
if ( $mischief_managed = 1 ) {
return $mischief_managed;
} else {
return 0;
}
}
The while() loop is the general strategy you need for the container
code. How you manage the risky bit is up to you (eval{} is a good idea
in many cases) but you need to take the resulting status (either a flag
variable like the made-up $mischief_managed above or $? or what have
you) and use that to control whether or not you keep looping.
--
Chris Devers
§G?I¾¢,<ú
- References:
- general retry function
- From: Ing. Branislav Gerzo
- general retry function
- Prev by Date:
eval without warnings - Next by Date:
Re: eval without warnings - Previous by thread:
general retry function - Next by thread:
Re: general retry function - Index(es):