Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.... }

In reply to Re: Best way to replace 'die' with 'warn' by Marshall
in thread Best way to replace 'die' with 'warn' by puterboy

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (4)
    As of 2020-10-20 12:18 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (210 votes). Check out past polls.