I haven't used the Weather module. Perl has a "redo" which
allows re-starting of a while loop() without re-evaluating
the stuff within the while(...). This is very useful for
doing "retries". For example, this POST will fail about one
out of every 5,000 times on my machine. I've never seen this
happen 2x in a row unless the web server is "hard down".
I think what you need is similar to this. Here I get a
clear return value that says "It didn't work". Maybe you get
something more indefinate like "I wanna die". If that is true, then
use eval{} and plug the success or fail value into the "redo" code.
my $max_retry =3;
RETRY: while (my $n_attempt=0, $parameter=<>)
{
my $req = POST 'http:/...blah..../',
[
action => '/db/',
param => "$parameter",
type => 'submit',
value => 'Search',
];
my $res = $ua->request($req);
# idea is to concentrate the "it didn't work" code to
# right here
unless ($res->is_success) ##1 of 5,000 case##
{
$n_attempt++;
print STDERR "attempt # $n_attempt for $parameter\n";
print STDERR "$parameter ERROR: Try# $n_attempt of $max_retry: "
+.
$res->status_line . "\n";
sleep(1);
redo RETRY if $n_attempt <= $max_retry;
print STDERR "$parameter ERROR: Try# $n_attempt of ".
"$max_retry FAILED: ".
$res->status_line . "\n";
next; #we "Give up" at this point! And read next
#parameter from <>
}
### this is the "good machine case..."
print $res->as_string if DEBUG_RAW;
......or whatever....
}