douglazb has asked for the wisdom of the Perl Monks concerning the following question:

I have a Perl script that will interrogate 400 domains. Occasionally a domain is not online, causing the program to die. Can I amend the program to not die, but resume the next domain in the array?
$query = "SELECT DISTINCT a.url FROM links_current a LEFT JOIN links_a +rchive b ON a.url = b.url WHERE b.url IS NULL ;"; $statement = $dbh->prepare($query) or error ("Cannot Prepare Select li +nks_current Statement: " . $dbh->errstr()); $statement->execute() or error ("Cannot Execute Select Distinct links_ +current Statement: " . $dbh->errstr()); my $arraycount = $statement->rows; # Fetch Each New Link (Record) Not Previous Archived Inside The Databa +se my $counter = 1; while (my $website = $statement->fetchrow_array()){ $mech->get($website)
or error ("Cannot Connect To Website $website: " . $statement->errstr());
$counter++; archive_article($title, $article, $website); archive_link($website); }

Replies are listed 'Best First'.
Re: Mechanize, Do Not Die, Do Next In Loop
by LanX (Saint) on May 10, 2013 at 02:48 UTC
    is  or error ("Cannot Connect To Website $website: " . $statement->errstr()); part of the code?

    if yes, then you seem to call a self-defined subroutine error() which dies.

    Either change the subroutine (whatever it's supposed to do) or replace error with warn.

    Or ask the guy who wrote the code for you! =)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re: Mechanize, Do Not Die, Do Next In Loop (autocheck)
by Anonymous Monk on May 10, 2013 at 04:00 UTC

    If you have autocheck on and its dying, use  eval { } to trap it, example

    my $ua = WWW::Mechanize->new( autocheck => 1 ); ... eval { $ua->get(...); 1 } or do { warn "Caught a fish: $@"; next LOOP; }

    Also, this is documented in WWW::Mechanize