I have a data structure that I got from this code.
my $name = $data->{Instances}->[0]->{Tags};
That data structure looks like this
$VAR1 = [
{
'Key' => 'Name',
'Value' => 'fl-demo'
},
{
'Value' => 'FL',
'Key' => 'state'
}
];
I’m trying to print the keys and values with this
foreach my $key (sort keys %$name) {
my $value = $name->{$key};
print "$key => $value\n";
}
I’m getting
Not a HASH reference at ./x.pl line 19.
>Solution :
The tags are returned as a list, not a hash. So you’re looking at doing something like this, instead, to iterate over them:
foreach my $tag (@$name) {
my $key = $tag->{Key};
my $val = $tag->{Value};
print "$key => $val\n";
}