以下代码适用于 Active Perl 5.14.2:
my %hzones = ();
#%hzones= (
# 'zone1' => {
# 'ns1' => 'ip1',
# 'ns1' => 'ip2',
# },
# 'zone2' => {
# 'ns1' => 'ip1',
# 'ns2' => 'ip2'
# }
#);
foreach my $k1 ( keys %hzones ) {
debug("# $k1",$d);
while ( my ($key, $value) = each($hzones{ $k1 }) ) { # Problem is here 217
while ( my ($nsname, $nsip) = each(%$value) ) {
debug("## $nsname , $nsip",$d);
}
# Creation de la zone et ajout dans infoblox
$session->add(createZone($k1)) or error("Add zone for ".$k1." failed: ",
$session->status_code(). ":" .$session->status_detail());
}
}
现在,如果我尝试在 RedHat 5.3 和 Perl 5.8.8 上使用此代码,则会出现以下错误:
Type of arg 1 to each must be hash (not hash element) at
./migration-arpa.pl line 217, near "}) "
Execution of ./migration-arpa.pl aborted due to compilation
errors.
问题:如何解决此错误?如何遍历我的哈希表?