in reply to Using REDO in Subroutine, need better way?

I'd be inclined to loop "for ever":

while (1) { # Get web page my $response = $ua->post( $page, \%form ); # Check for errors if ($response->is_success) { $data = $response->content; return \$data; } sleep 100; }

That is then easy to turn into a loop for some maximum number of times with error handling by falling out the bottom of the loop.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Using REDO in Subroutine, need better way?
by awohld (Hermit) on Oct 09, 2006 at 03:59 UTC
    Here is what I ended up with, I error out after 3 hours and send out an alert to my email if it fails.
    my $terminal_failure = 0; while (1) { # Get page my $response = $ua->post( $page, \%form ); if ($response->is_success) { $data = $response->content; last; } sleep 100; $terminal_failure++; # Die if no data for 3 hours send email alert. if ( $terminal_failure == 108 ) { my $failure = $response->status_line; my $msg = MIME::Lite->new( From =>'me@alerter.com', To =>'my@email.com Subject =>"", Data => "HTML download fail: $failure" ); $msg->send; die $failure; } }