我对此一无所知。由于我们的Linux标准仍然是RHEL 6,因此我必须使用旧版本的Perl。所以我有Perl 5.10.1。我在5.14中开发了脚本,并且效果很好。迁移到RHEL和较旧的Perl时,会遇到麻烦。
这是作为$ response带回来的信息的DataDump,其后是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版(工作)
while (($key, $value) = each($response->{'response'}{'scanners'} )){
switch ($value->{'status'}){
case 1 {print "Status OK \t\t\t"}
case 2 {print " !! CLOSED !! \t\t\t"}
case 4 {print " !! TIMEOUT !! \t\t\t"}
case 16384 {print " ** DISABLED **\t\t\t"}
case 1024 {print " Updating Plug-Ins \t\t\t"}
case 1025 {print " ** Updating Plug-Ins **\t\t"}
case 1281 {print " Attempting to Update\t\t"}
case 256 {print " !! Out of Date !! \t\t\t"}
case 257 {print "Plug-Ins Out of Sync !! \t\t"}
else { print "Status BAD ($value->{'status'}) \t\t"}
}
print "$value->{'name'} $value->{'description'} \n";
}
PERL版本5.10.1(无效)
while (($key, $value) = each($response->{'response'}{'scanners'} )){
错误并带有错误:每个参数的类型1必须在以下位置为哈希值(而不是哈希元素)
更改为:
while (($key, $value) = each(%{$response->{'response'}{'scanners'}} )){
允许其运行,但在以下位置以“非散列引用”停止
$response->{'response'}{'scanners'}
包含对数组的引用,因此您的代码等效于以下内容:
while (my ($key, $value) = each(@{ $response->{response}{scanners} })) {
...
}
但是,each
不适用于5.10中的数组。以下是等效的:
for my $key (0..$#{ $response->{response}{scanners} }) {
my $value = $response->{response}{scanners}[$key];
...
}
由于您实际上并未使用$key
,因此您也可以使用以下内容:
for my $value (@{ $response->{response}{scanners} }) {
...
}
注意:建议您不要使用each($ref)
。除了向后兼容问题之外,它是实验性的,不适用于某些特殊的哈希和数组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句