I'm trying to use Parallel::Iterator to fetch a bunch of webpages using basic authentication, then write the contents back to my local disk. I can' seem to pass it the correct data. Can anyone help?
#!/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); }

In reply to Parallel::Iterator to get multiple pages by Elwood1

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.