我有一個問題,我希望你可以幫忙嗎?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