in reply to Grabbing many webpages with foreach

You really need to use strict. If you had strict on, you'd see that $A_list was not declared anywhere. By default, a foreach loop puts each element into $_ unless you give it another variable to use. You should also check the return status of your open call to make sure there are no errors.

It also doesn't make much sense to put use LWP::Simple; and use HTML::Strip in the middle of your loop -- use statements are executed at compile time and modules are (usually) only loaded once.

With that in mind, this should get you started.

#!/usr/bin/perl use strict; use warnings; use LWP::Simple; #open text file and fill array open(MYINPUTFILE, "<A-list") or die "Can't open A-list: $!"; my(@A_in) = <MYINPUTFILE>; # read file into list #remove whitespace my @A_list = map { s/^\s+//; s/\s+$//; $_ } @A_in; close(MYINPUTFILE); #fetch each webpage foreach my $num(@A_list) { chomp $num; my $url = "$num"; my $content = get $url; die "Couldn't get $url" unless defined $content; print $content; }

Replies are listed 'Best First'.
Re^2: Grabbing many webpages with foreach
by monkeybus (Acolyte) on Jun 14, 2007 at 03:17 UTC
    Thank you very much indeed.