in reply to Re: Ending a loop of content of LWP's get-function
in thread Ending a loop of content of LWP's get-function
this gives only one line of content from the retrieved file. It loops till it has found one occurence of the matched pattern, then quits the loop. I'd like it to continue until the whole file has been matched. Is it possible to use "length" to achieve this?#!/usr/bin/perl -w use warnings; use strict; use LWP::Simple; my ($html, $url); my $count = 0; my @urls = ( "http://localhost:8080/html.htm", ); for my $url (@urls) { my $html = get($url) or die "Couldn't fetch page."; $html =~ m{<(a class=\"smallV110\" href=\"/)(.*?)\">} || die "couldn't + match"; #match regexp and capture backreference to $2, or die with e +rror $url = $2; print "$url\n"; $count++; print "$count\n"; }
This code gives, as in the case above, one matched result from the retrieved file, then quits with the error:#!/usr/bin/perl -w use warnings; use strict; use LWP::Simple; my ($html, $url); my $count = 0; my $new_url; my @urls = ( "http://localhost:8080/html.htm", ); while (@urls) { my $url = shift(@urls); my $html = get($url) or die "Couldn't fetch page."; $html =~ m{<(a class=\"smallV110\" href=\"/)(.*?)\">} || die "couldn't + match"; #match regexp and capture backreference to $2, or die with e +rror $url = $2; print "$url\n"; push @urls, $new_url; # or @new_urls }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Ending a loop of content of LWP's get-function
by ikegami (Patriarch) on Mar 27, 2009 at 17:45 UTC |