M
mUs
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
}
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
}