0

I have the following very simple piece of code:

#!/usr/bin/perl

use strict;
use warnings;

use WWW::Mechanize::Timed;
my $ua = WWW::Mechanize::Timed->new();
my $url = 'www.stackoverflow.com';

$ua->get($url);    
print "Total time: " . $ua->client_total_time . "\n";
print "Elapsed time: " . $ua->client_elapsed_time . "\n";

The error I am getting:

When running the program I sometimes get the following error, it does not happen all the time, its seems to appear intermittently.

Use of uninitialized value in addition (+) at /usr/local/share/perl/5.10.1/WWW/Mechanize/Timed.pm line 52.

Is there something obvious I am overlooking, as I cant understand why this error is occurring, let alone why it only happens sometimes?

Your help is much appreciated, many thanks

4

1 回答 1

2

我相信问题在于

my $url = 'www.stackoverflow.com';

不是实际的 URL。这只是一个主机名。您是说您的程序有时可以在不指定http://方案的情况下运行吗?你需要

my $url = 'http://www.stackoverflow.com';

此外,您想检查返回代码->get(),或添加autocheck => 1到构造函数。::Mechanize 历史中的某个时刻成为默认设置,但我不知道您使用的是哪个版本。

于 2013-03-06T22:52:16.410 回答