in reply to catching failures and retrying

Create a wrapper function (we'll call it wrapper) that returns true on success and false on failure. It might look like this, then:

sub wrapper { eval { ## do some stuff that might die }; if ($@) { ## handle some error things, die if unrecoverable return 0; # returns false if recoverable } return 1; #returns true if we should retry }

To retry a few times before giving up, then, you may write:

use constant RETRIES => 3; for (1..RETRIES) { last if wrapper() }

In this way, you will try up to three times before the loop will exit. If you need more complexity, you might expand to something like:

use constant RETRIES => 3; our $give_up = 0; for (1..RETRIES) { $give_up = 0; last if wrapper(); $give_up = 1; } die ('Tried '.RETRIES.' times without success. Giving up.') if $give_up;

This will set $give_up on each try in such a way that a sucessful run will result in $give_up == 0, while a failed run will result in $give_up == 1. We can then check that value to see if we gave up or no.

radiantmatrix
require General::Disclaimer;
s//2fde04abe76c036c9074586c1/; while(m/(.)/g){print substr(' ,JPacehklnorstu',hex($1),1)}