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

How can you make www::mech not die when it runs into an error? I'm trying to create a link bot for my site and it comes across a specific w3c link that ALWAYS kills the script with Software error: Error GETing http://validator.w3.org/check?uri=referer: Precondition Failed at getlinks.pl line 216

My current script is

foreach my $newlink (keys %templinks) { my $mech = WWW::Mechanize->new( autocheck => 1 ); $mech->get( $newlink ); foreach ($mech->find_all_links) { $templinks{$_->url} = $_->url; } }
Without manually removing this bad link from the script, how can I make it SKIP this and any future links that it can't load for whatever reason and move on to the next without warnings or errors?

Replies are listed 'Best First'.
Re: how to make www::mech not die on errors
by Corion (Patriarch) on Apr 06, 2007 at 22:13 UTC

    Leave out the autocheck => 1 in your constructor. Then all problems in WWW::Mechanize will be warnings instead of fatal errors. This of course leaves error checking up to your application.