我有一个问题,我希望你可以帮忙吗?Perl WWW ::机械化存储网址,除非它已被发现
foreach my $url (keys %{$newURLs}) {
# first get the base URL and save its content length
$mech->get($url);
my $content_length = $mech->response->header('Content-Length');
# now iterate all the 'child' URLs
foreach my $child_url (@{ $newURLs->{$url} }) {
# get the content
$mech->get($child_url);
# compare
if ($mech->response->header('Content-Length') != $content_length) {
print "$child_url: different content length: $content_length vs "
. $mech->response->header('Content-Length') . "!\n";
#HERE I want to store the urls that are found to have different content
#lengths to the base url
#only if the same url has not already been stored
} elsif ($mech->response->header('Content-Length') == $content_length) {
print "Content lengths are the same\n";
#HERE I want to store the urls that are found to have the same content
#length as the base url
#only if the same url has not already been stored
}
}
}
我遇到的问题:
正如你可以在代码中看到上面我想存储的URL取决于如果内容长度相同或不同,所以我会最终得到一组具有与其基本URL不同的内容长度的URL,并且最终将得到另一组具有与其基本URL相同内容长度的URL。
我知道如何做到这一点很容易使用数组
push (@differentContentLength, $url);
push (@sameContentLength, $url);
但我将如何去使用这个散列(或另一种首选方法)?
我仍然得到与哈希交手所以你的帮助将非常感激,
非常感谢
您应该在您的循环中添加右括号。 – simbabque 2013-02-13 12:18:09
@simbabque - 是你的权利,道歉 – 2013-02-13 12:25:07