brothers,

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;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"; } } }

In reply to for loop over large BLOCK keeps failing by cdherold

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.