#!/usr/bin/perl
use strict;
use warnings;
my %ani_hash = (
'machine_results' => [
{
'status' => 'Failed install',
'machine' => '23.73.134.235',
'seconds' => '20',
'try' => '1'
},
{
'status' => 'Failed install',
'machine' => '23.73.134.140',
'seconds' => '20',
'try' => '1'
}
],
'description' => 'MC-5897'
);
get_elements( \%ani_hash );
sub get_elements
{
my $hashref1 = shift;
my %hashref2 = %$hashref1;
print "%hashref1\n";
foreach my $machineresult ( keys %hashref2 ) {
foreach my $machineresult2 ( keys %{ $hashref2{$machineresult} } ) {
print "$hashref2{$machineresult}{$machineresult2}\n";
}
}
}
Output:
HASH(0x1e9fe58)
Not a HASH reference at ./hashref.pl line 62.
Can't use string ("MC-5897") as a HASH ref while "strict refs" in use at ./hashref.pl line 62.
I want to loop through all the key value pairs and get their values. I don't want to use the dumper method to get the values, I want to get these by looping method. Any help would be appreciated. Thanks
I did this to fix the issue and get the contents of 'machine_results'.
print "description: $hashref2{description}\n";
foreach my $machineresult( sort keys%hashref2){
foreach my $array (@{ $hashref2{$machineresult} }){
foreach my $array1( sort keys%{$array} ){
print "key is $array1 and it's value is $array->{$array1}`",
"enter code here`\n";
}
print "\n";
}
}