Not a HASH reference in Perl

Viewed 502

I am trying to fix some old code that is not working anymore with a Perl new version. Unfortunately, I have never coded in Perl yet.

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 "})"

I tried to fix it by dereferencing the $Body but now it's not accepted to initialize my array @IDs.

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

Not a HASH reference

Here is the content of the $Body if I dump it.

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

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

Could you help me to put the content of the $Body variable inside the array?

1 Answers

You can dereference the array with @{}. I see no need to use values here:

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