【发布时间】:2013-01-29 08:00:40
【问题描述】:
我有一个问题希望您能提供帮助?
这是我在理解哈希引用方面需要帮助的最后一部分
代码:
my $content_lengths; # this is at the top
foreach my $url ( # ... more stuff
# compare
if ( $mech->response->header('Content-Length') != $content_length ) {
print "$child_url: different content length: $content_length vs "
. $mech->response->header('Content-Length') . "!\n";
# 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
$content_lengths->{$url}->{'different'}->{$child_url} = $mech->response->header('Content-Length');
} elsif ( $mech->response->header('Content-Length') == $content_length ) {
print "Content lengths are the same\n";
# 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
$content_lengths->{$url}->{'equal'}->{$child_url} = $mech->response->header('Content-Length');
}
使用 Data::Dumper 的样子
$VAR1 = {
'http://www.superuser.com/' => {
'difference' => {
'http://www.superuser.com/questions' => '10735',
'http://www.superuser.com/faq' => '13095'
},
'equal' => {
'http://www.superuser.com/ ' => '20892'
}
},
'http://www.stackoverflow.com/' => {
'difference' => {
'http://www.stackoverflow.com/faq' => '13015',
'http://www.stackoverflow.com/questions' => '10506'
},
'equal' => {
'http://www.stackoverflow.com/ ' => '33362'
}
}
};
我需要什么帮助:
我需要帮助了解访问散列引用中不同部分的各种方法,并使用它们来执行操作,例如打印它们。
例如,我如何从哈希引用中打印所有 $url(即来自 Data::Dumper 的 http://www.superuser.com/ 和 http://www.stackoverflow.com/)
我如何打印所有 $child_url 或来自$child_url 的特定的/子集 等等?
非常感谢您的帮助,
非常感谢
【问题讨论】:
标签: perl hash www-mechanize hashref