Elwood1 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use LWP::UserAgent; use Parallel::Iterator qw/iterate_as_array/; # a list of pages to fetch my @urls =( [name1,user1,password1,url1,enable1], [name2,user2,password2,url2,enable2], [name3,user3,password3,url3,enable3], ); my $ua = LWP::UserAgent->new(); # this worker fetches a page and returns the HTTP status code my $worker = sub { my $index = shift; my $name = shift; my $username = shift; my $pass = shift; my $url = shift; $ua->credentials($name,$url,$username,$pass); my $response = $ua->get($url); my $content = $response->decoded_content(); return ( $index, $response->code(), $content ); }; my %options = (); $options{workers} = 5; # Fetch pages in parallel my @status_codes = iterate_as_array(\%options, $worker, \@urls ); # Display results my %codes = (); @codes{@urls} = @status_codes; # output results my $format = "%-40s %s\n"; printf( "$format", 'URL', 'Status' ); foreach my $url ( sort keys %codes ) { open (FILEOUT, '>', $name); print FILEOUT $content; close (FILEOUT); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parallel::Iterator to get multiple pages
by kcott (Archbishop) on Aug 25, 2013 at 04:21 UTC | |
by Elwood1 (Initiate) on Aug 25, 2013 at 05:32 UTC | |
by afoken (Chancellor) on Aug 25, 2013 at 10:29 UTC | |
by Elwood1 (Initiate) on Aug 25, 2013 at 10:32 UTC | |
|
Re: Parallel::Iterator to get multiple pages
by ww (Archbishop) on Aug 25, 2013 at 01:38 UTC | |
by Elwood1 (Initiate) on Aug 25, 2013 at 05:37 UTC | |
|
Re: Parallel::Iterator to get multiple pages
by poj (Abbot) on Aug 25, 2013 at 10:59 UTC | |
by McA (Priest) on Aug 25, 2013 at 12:11 UTC |