Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 5.10.1的错误类型arg 1 to each必须是散列_Perl_Hash - Fatal编程技术网

Perl 5.10.1的错误类型arg 1 to each必须是散列

Perl 5.10.1的错误类型arg 1 to each必须是散列,perl,hash,Perl,Hash,我对此束手无策。我不得不使用较旧版本的Perl,因为我们的Linux标准仍然是RHEL 6。所以我有Perl 5.10.1。我在5.14中开发了我的脚本,效果非常好。移动到RHEL和较旧的Perl it barfs 下面是作为$response返回的信息的数据转储,后面是5.14中使用的代码和我在5.10.1中尝试过的内容。任何帮助都将不胜感激 response => { md5 => { organiz

我对此束手无策。我不得不使用较旧版本的Perl,因为我们的Linux标准仍然是RHEL 6。所以我有Perl 5.10.1。我在5.14中开发了我的脚本,效果非常好。移动到RHEL和较旧的Perl it barfs

下面是作为$response返回的信息的数据转储,后面是5.14中使用的代码和我在5.10.1中尝试过的内容。任何帮助都将不胜感激

response   => {
                  md5 => {
                    organizations => "b157f81f9469e88fd1ac2435559f558e",
                    scanners => "40e782276cc521ef799cc111a9472cf4",
                    zones => "a41b4d543756320418fce473d97a3b8d",
                  },
                  organizations => [
                    { description => "", id => 1, name => "Our Corporation" },
                  ],
                  scanners => [
                    { description => "", id => 5, name => "BR549-A", status => 1 },
                    {
                      description => "Test VM Scanner in BFE",
                      id => 16,
                      name => "BFENessus01",
                      status => 1,
                    },
                    {
                      description => "Our other Nessus Scanner VM",
                      id => 17,
                      name => "OHTHERNESSUS01",
                      status => 1,
                    },
                    { description => "", id => 49, name => "NYCNESSUS02", status => 1 },
                    { description => "", id => 50, name => "LAX1NESSUS03", status => 1 },
                    { description => "", id => 51, name => "LAX1NESSUS04", status => 1 },
                    { description => "", id => 52, name => "LAX1NESSUS05", status => 1 },
                    { description => "", id => 54, name => "MK-NESSUS", status => 1 },
                    {
                      description => "Networking team's scanner",
                      id => 55,
                      name => "NETEAMNESSUS06",
                      status => 1,
                    },
                },
  timestamp  => 1400177639,
  type       => "regular",
  warnings   => [],
}                   
PERL版本5.14(工作)

PERL版本5.10.1(不工作)

errors out with error:each的arg 1类型必须是hash(不是hash元素)

改为:

while (($key, $value) = each(%{$response->{'response'}{'scanners'}} )){

允许它运行,但在

$response->{'response'}{'scanners'}
包含对数组的引用时停止,因此您的代码相当于以下内容:

while (my ($key, $value) = each(@{ $response->{response}{scanners} })) {
   ...
}
for my $value (@{ $response->{response}{scanners} }) {
   ...
}
但是,
每个
在5.10中的数组上都不起作用。以下是等效的:

for my $key (0..$#{ $response->{response}{scanners} }) {
   my $value = $response->{response}{scanners}[$key];
   ...
}
由于您实际上没有使用
$key
,因此也可以使用以下选项:

while (my ($key, $value) = each(@{ $response->{response}{scanners} })) {
   ...
}
for my $value (@{ $response->{response}{scanners} }) {
   ...
}


注意:我建议不要使用
每个($ref)
。除了向后兼容性问题外,它是实验性的,并且不适用于某些特殊的哈希和数组。

$response->{'response'}{'scanners'}
包含对数组的引用,因此您的代码相当于以下内容:

while (my ($key, $value) = each(@{ $response->{response}{scanners} })) {
   ...
}
for my $value (@{ $response->{response}{scanners} }) {
   ...
}
但是,
每个
在5.10中的数组上都不起作用。以下是等效的:

for my $key (0..$#{ $response->{response}{scanners} }) {
   my $value = $response->{response}{scanners}[$key];
   ...
}
由于您实际上没有使用
$key
,因此也可以使用以下选项:

while (my ($key, $value) = each(@{ $response->{response}{scanners} })) {
   ...
}
for my $value (@{ $response->{response}{scanners} }) {
   ...
}


注意:我建议不要使用
每个($ref)
。除了向后兼容性问题外,它是实验性的,不能与一些特殊的哈希和数组一起使用。

(您可以在本地安装自己的Perl版本)(您可以在本地安装自己的Perl版本)