我有一个问题希望你能帮忙?
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,我会结束加上另一组与其基本网址具有相同内容长度的网址。
我知道如何使用数组轻松做到这一点
push (@differentContentLength, $url);
push (@sameContentLength, $url);
但是我将如何使用哈希(或其他首选方法)来解决这个问题?
我仍然在处理哈希,所以你的帮助将不胜感激,
多谢