Hello sunil9009,
You are correct. If you know that each anonymous hash in the array contains exactly one key, then
my @hosts = map { keys %$_ } @{ $hashref->{Inventory}{host} };
is all you need. My concern was that the anonymous hash might be expanded to contain multiple keys. My idea was to ensure you get only the first key, by specifying the zero-subscript element of the list returned by keys %$_. But my “solution” doesn’t work, because the order of keys in a hash is unpredictable. To be on the safe side, I should have used something like:
my @hosts = grep { /^host/ } map { keys %$_ } @{ $hashref->{Inventory} +{host} };
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^3: getting array value from anonymous hash
by Athanasius
in thread getting array value from anonymous hash
by sunil9009
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |