Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > In loop wait for function return

Reply
Thread Tools

In loop wait for function return

 
 
mUs
Guest
Posts: n/a
 
      08-09-2003
I would like to loop through a few URL's utilizing the LWP::Simple get function.
Using the existing 'logic' ( or lack thereof ) is there a way to have the
script wait before executing the next iteration of the for loop. At the moment
the 'get' function does not have enough time to complete its' request.
I looked into fork, wait, exec, etc but those don't seem to be what i'm looking
for. I though 'eval' would do it but it doesn't. thanks


#!/usr/bin/perl -w

use strict;
use diagnostics;
use LWP::Simple;
require HTML::TokeParser;

my $url = 'http://localhost/page.html';
my $url2 = 'http://localhost/page2.html';
my $url3 = 'http://localhost/page3.html';
my @urls = qq($url $url2 $url3);

# yes, of course this works
#die "LWP::Simple is empty: $! " unless ( parse_page(my $webPage = get($url)));

# loop does not give LWP::Simple function get enough time to
# return before looping, just dies

for my $page (@urls) {
die "cant get web page: $!\n" unless ( my $webPage = get($page));
# eval does not die, exits with success but nothing sent to
# function
#eval {($webPage = get($page));}; die $@ if $@; # returns ok
#eval {&parse_page($webPage = get($page));}; die $@ if $@; #return ok but
# nothing send to function, script dies
}


sub parse_page {
shift ,etc
}
 
Reply With Quote
 
 
 
 
Gregory Toomey
Guest
Posts: n/a
 
      08-10-2003
"mUs" <cmustard_!(E-Mail Removed)> wrote in message
news:X2dZa.111703$(E-Mail Removed)...
> I would like to loop through a few URL's utilizing the LWP::Simple get

function.
> Using the existing 'logic' ( or lack thereof ) is there a way to have the
> script wait before executing the next iteration of the for loop. At the

moment
> the 'get' function does not have enough time to complete its' request.
> I looked into fork, wait, exec, etc but those don't seem to be what i'm

looking
> for. I though 'eval' would do it but it doesn't. thanks


The get function returns a string, usually containing HTML. It generally
takes 1-2 seconds to run for me.

If you are saying that the web server at the other end takes a long time to
return you request, or does not return at all, then maybe he URL is wrong or
the web server is overoaded? Have you tried typing the URLs in a browser?

Forking of subprocesses does not solve the underlying problem.

gtoomey




 
Reply With Quote
 
 
 
 
Eric J. Roode
Guest
Posts: n/a
 
      08-10-2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

mUs <cmustard_!(E-Mail Removed)> wrote in
news:X2dZa.111703$(E-Mail Removed):

> I would like to loop through a few URL's utilizing the LWP::Simple get
> function. Using the existing 'logic' ( or lack thereof ) is there a
> way to have the script wait before executing the next iteration of the
> for loop. At the moment the 'get' function does not have enough time
> to complete its' request. I looked into fork, wait, exec, etc but
> those don't seem to be what i'm looking for. I though 'eval' would do
> it but it doesn't. thanks


The script *is* waiting for the 'get' to return before going on to the next
iteration of the loop. What are you seeing (versus what you're expecting)
that is causing you to think otherwise?

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPzWdRGPeouIeTNHoEQJ+kACeK1PREMpNGus4MkEAcJc0rR 7pi6sAoONf
MUsJJ+LnlbeQNSOZSZDbqpuQ
=Ila7
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Bart Lateur
Guest
Posts: n/a
 
      08-10-2003
Eric J. Roode wrote:

>mUs <cmustard_!(E-Mail Removed)> wrote in
>news:X2dZa.111703$(E-Mail Removed):
>
>> I would like to loop through a few URL's utilizing the LWP::Simple get
>> function. Using the existing 'logic' ( or lack thereof ) is there a
>> way to have the script wait before executing the next iteration of the
>> for loop. At the moment the 'get' function does not have enough time
>> to complete its' request.


>The script *is* waiting for the 'get' to return before going on to the next
>iteration of the loop. What are you seeing (versus what you're expecting)
>that is causing you to think otherwise?


To the OP: check the return status of the request. You won't be able to
do that using get(), but getstore(), which will save the retrieved data
as a file, will at least return the status code. If it's not 200,
something went wrong. More elaborate scripts using LWP::UserAgent can
return you the complete headers.

--
Bart.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
calling wait outside of loop puzzlecracker Java 5 05-08-2006 12:59 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
How can I call a subroutine / function and not wait for it to return? bayxarea-usenet@yahoo.com Perl Misc 9 01-27-2005 04:24 PM
How to make "fork/wait" to WAIT longer? Huey C Programming 1 03-01-2004 02:01 PM



Advertisments