in reply to Re^2: handling WWW::Mechanize Error GETing
in thread handling WWW::Mechanize Error GETing
Hi,
Using if($@) is unreliable,
The correct pattern is
$temp = eval { $mech->get($imgsrc) }; if( not $temp ){ ... }
But we're using mech so we dont need to store the response in $temp
So even better
eval { $mech->get( $imgsrc ); }; if( not $mech->res->is_success ){ ... }
Or even better
if( not eval { $mech->get( $imgsrc ); 1 } ){ ... }
Or simply the generic version , it doesn't rely on $@
eval { $mech->get( $imgsrc ); 1 } or do { ... };
For explanation why using if($@) is unreliable see Devel::EvalError -- Reliably detect if and why eval() failed
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: handling WWW::Mechanize Error GETing
by haukex (Archbishop) on Dec 29, 2016 at 11:25 UTC | |
by Anonymous Monk on Dec 29, 2016 at 21:59 UTC |