How would one make multiple attempts using LWP::UserAgent? I have the following snipped of code:
$req = HTTP::Request->new(GET => $reqstr); $req->authorization_basic('username', 'password'); $res = $ua->request($req);$req = HTTP::Request->new(GET => $reqstr); $req->authorization_basic('username', 'password'); $res = $ua->request($req); my $title = $ua->request($req)->header('Title'); if (($res->is_success) && ($title ne 'Empty result')) { open(OUT,"> $outfile") || die "Could not open $outfile for writing +: $!\n"; print OUT $ua->request($req)->content; close OUT; exit; ## Do not output if there were empty results } elsif ($res->status_line eq '200 OK') { print STDOUT "There were empty results\n"; #$attempts++; ## Some other error } else { print STDOUT "Error: " . $res->status_line . "\n"; $attempts++; sleep 10; } my $title = $ua->request($req)->header('Title'); while ($attempts < 4) { if (($res->is_success) && ($title ne 'Empty result')) { ## Open file handle for output file open(OUT,"> $outfile") || die "Could not open $outfile for writing +: $!\n"; print OUT $res; close OUT; exit; } elsif ($res->status_line eq '200 OK') { print STDOUT "There were empty results\n"; } else { print STDOUT "Error: " . $res->status_line . "\n"; }
My problem lies where I would want the loop to repeat if it's the third case (when it's equivalent to $res->is_error).

In reply to Looping LWP::UserAgent by Anonymous Monk

Title:
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, details, 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, summary, 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.