cdherold has asked for the wisdom of the Perl Monks concerning the following question:
the code I have below works great except for one thing, when I put a for loop around it (the first one that goes to $loop=4) it fails completely. Without the loop it goes along and finds all the links on a given webpage, stores those links in an array and then goes into each link to determine if the news article there is something I want to keep ... if it is, the article gets copied and mailed to me.
why does it keep crashing when I put the for loop around the entire program???!! When I run the for loop by itself at top with a simple print statement BLOCK it goes ahead and executes everything as expected, but it fails when I make the entire rest of the program the BLOCK.
I need the entire program BLOCK to be reiterated over and over so I can keep up to date on the press releases, but without having to go and call the program. I intend to put a "sleep" statement in so that it only loops every hour, but if I can't get it to loop then I guess I won't have to worry about that.
the script has been editted for brevity. the loop to 4 is just for testing purposes.
i thought very hard about not including this length of code, but think it is necessary to address the problem. Let me know if I have overstepped proper posting length bounds. thanks, cdherold
for ( $loop=0; $loop=4; $loop++) { use LWP::UserAgent; use HTML::LinkExtor; use URI::URL; $url = "http://www.prnewswire.com"; $ua = new LWP::UserAgent; my @img = (); sub callback { my($tag, %attr) = @_; return if $tag ne 'a'; # we only look closer at written + documents, not images push(@img, values %attr); + } $p = HTML::LinkExtor->new(\&amp;amp;amp;amp;amp;amp;amp;amp;amp; +callback); $res = $ua->request(HTTP::Request->new(GET => $url), sub {$p->parse($_[0])}); my $base = $res->base; @img = map { $_ = url($_, $base)->abs; } @img; splice(@img,-20); $links = join(",", @img), "\n"; $count++ while $links =~ /http/gsm; for ($i = 0; $i < $count; $i++) { use LWP::Simple; $body = get("@img[$i]"); + if ($body =~ /inmx/gsmi) { + $mailprog = '/usr/sbin/sendmail'; + $recipient = 'xx@here.com'; + open (MAIL, "|$mailprog -t"); + print MAIL "To: $recipient\n"; + print MAIL "$body\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: for loop over large BLOCK keeps failing
by perlmonkey (Hermit) on May 02, 2001 at 11:54 UTC | |
|
Re: for loop over large BLOCK keeps failing
by busunsl (Vicar) on May 02, 2001 at 12:03 UTC | |
by cdherold (Monk) on May 02, 2001 at 12:19 UTC | |
by busunsl (Vicar) on May 02, 2001 at 12:41 UTC | |
by jeroenes (Priest) on May 02, 2001 at 13:09 UTC | |
by cdherold (Monk) on May 02, 2001 at 13:07 UTC | |
by chipmunk (Parson) on May 02, 2001 at 20:55 UTC | |
| |
by cLive ;-) (Prior) on May 02, 2001 at 12:46 UTC | |
|
Re: for loop over large BLOCK keeps failing
by hugonz (Initiate) on May 02, 2001 at 21:13 UTC |