简体   繁体   English

不是 Perl 中的 HASH 引用

[英]Not a HASH reference in Perl

I am trying to fix some old code that is not working anymore with a Perl new version.我正在尝试修复一些不再适用于 Perl 新版本的旧代码。 Unfortunately, I have never coded in Perl yet.不幸的是,我从来没有用 Perl 编码过。

This line is currently causing an issue.这条线路目前引起了问题。 I have a compilation error.我有一个编译错误。

my @IDs = values($Body->{'ConfigItemSearchResponse'}->{'ConfigItemIDs'});

Experimental values on scalar is now forbidden at ./CMDBcertificateCheck.pl line 266. Type of arg 1 to values must be hash or array (not hash element) at ./CMDBcertificateCheck.pl line 266, near "})"现在禁止在 ./CMDBcertificateCheck.pl 第 266 行使用标量的实验值。在 ./CMDBcertificateCheck.pl 第 266 行,“})”附近,值的 arg 1 类型必须是散列或数组(不是散列元素)

I tried to fix it by dereferencing the $Body but now it's not accepted to initialize my array @IDs.我试图通过取消引用 $Body 来修复它,但现在不接受初始化我的数组 @IDs。

my @IDs = values(%{$Body->{'ConfigItemSearchResponse'}->{'ConfigItemIDs'}});

Not a HASH reference不是 HASH 参考

Here is the content of the $Body if I dump it.如果我转储它,这是 $Body 的内容。

print Dumper($Body->{'ConfigItemSearchResponse'}->{'ConfigItemIDs'});

$VAR1 = [ '646', '650', '2178', '2179' ]; $VAR1 = ['646', '650', '2178', '2179'];

Could you help me to put the content of the $Body variable inside the array?你能帮我把$Body变量的内容放在数组中吗?

You can dereference the array with @{} .您可以使用@{}取消引用数组。 I see no need to use values here:我认为没有必要在此处使用

my @IDs = @{ $Body->{'ConfigItemSearchResponse'}->{'ConfigItemIDs'} };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM