From: John on
Hi

I have

use WWW::Mechanize;
my $agent=WWW::Mechanize->new(autocheck => 1);
my ($url,$response,$content);
$url="http://www.example.com";
$agent->get($url); # main page
if (defined $agent) { whatever ...} else {print 'cannot connect'}

I get an error message if I cannot connect. I thought the if (defined
$agent) would catch this but it does not. Why?

Regards
John



From: J�rgen Exner on
"John" <john1949(a)yahoo.com> wrote:
>I have
>
>use WWW::Mechanize;
>my $agent=WWW::Mechanize->new(autocheck => 1);
>my ($url,$response,$content);
>$url="http://www.example.com";
>$agent->get($url); # main page
>if (defined $agent) { whatever ...} else {print 'cannot connect'}
>
>I get an error message if I cannot connect. I thought the if (defined
>$agent) would catch this but it does not. Why?

Where did you get the idea the $agent object would become undef if the
get() method can't connect?
See section "Status Methods" in the documention of WWW::Mechanize for
how to check for errors.

jue
From: John on

"J�rgen Exner" <jurgenex(a)hotmail.com> wrote in message
news:dmfjq5tmt4d7408pabc2d33puojvgnlkmr(a)4ax.com...
> "John" <john1949(a)yahoo.com> wrote:
>>I have
>>
>>use WWW::Mechanize;
>>my $agent=WWW::Mechanize->new(autocheck => 1);
>>my ($url,$response,$content);
>>$url="http://www.example.com";
>>$agent->get($url); # main page
>>if (defined $agent) { whatever ...} else {print 'cannot connect'}
>>
>>I get an error message if I cannot connect. I thought the if (defined
>>$agent) would catch this but it does not. Why?
>
> Where did you get the idea the $agent object would become undef if the
> get() method can't connect?
> See section "Status Methods" in the documention of WWW::Mechanize for
> how to check for errors.
>
> jue

Many thanks.

Got it at $agent->success() or $agent->status();

Regards
John