Thankyou for your quick reply, and for the pointers to push and unshift.
I'm still struggling with getting it work correctly, though. I've tried both of your suggestions, with two different results:
#!/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 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?
the other example gives a more grave 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 }
This code gives, as in the case above, one matched result from the retrieved file, then quits with the error:
Use of uninitialized value $url in pattern match (m//) at C:/Perl/lib/LWP/Simple.pm line 131. Couldn't fetch page. at retrieve.pl line 13.
I should note that I use ActivePerl, though I doubt very much that this is the cause of the latter problem. Again, I appreciate any help!

In reply to Re^2: Ending a loop of content of LWP's get-function by turbolofi
in thread Ending a loop of content of LWP's get-function by turbolofi

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.