Prev: FAQ 6.18 Why don't word-boundary searches with "\b" work for me?
Next: Perl & Get web content Perl-Function [Expert]
From: John on 24 Mar 2010 03:12 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 24 Mar 2010 03:30 "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 24 Mar 2010 04:33
"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 |