user2996524
user2996524

Reputation: 59

How to retry a loop in perl

I am doing a Eval to check whether if server goes down

    eval{
      foreach(){
        Processing 10,000 UPCS in API one by one
        }
      };
    if($@){
      continue; 
      sleep(1200);
    }

The above code works fine but the problem is if server goes down it is skipping the current UPC(Loop) and it id processing the next UPC(Loop).

Instead of skipping the UPC(Loop) i have to retry the same upc if server goes down?

Upvotes: 1

Views: 1108

Answers (1)

ysth
ysth

Reputation: 98388

Move the eval into the loop and use redo:

foreach ... {
    eval {
    };
    if ($@) {
        sleep 1200;
        redo;
    }
}

though I'm not sure what your continue was supposed to be doing; I doubt it did what you expected.

Upvotes: 3

Related Questions