Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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).$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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looping LWP::UserAgent
by ikegami (Patriarch) on Jun 07, 2005 at 00:46 UTC | |
|
Re: Looping LWP::UserAgent
by tchatzi (Acolyte) on Jun 07, 2005 at 09:26 UTC |