I am creating an xml to pass to an API and the API returns this (data dumped):
(
"Data::Dump",
{
SiteDevices => {
"device" => {
1102 => { address => "1.2.3.4", riskfactor => "1.0", riskscore => "0.0" },
1136 => { address => "1.2.3.5", riskfactor => "1.0", riskscore => "0.0" },
20491 => { address => "1.2.3.6", riskfactor => "1.0", riskscore => "0.0" },
129644 => { address => "1.2.3.7", riskfactor => "1.0", riskscore => "0.0" },
129645 => { address => "1.2.3.8", riskfactor => "1.0", riskscore => "0.0" },
130408 => { address => "1.2.3.9", riskfactor => "1.0", riskscore => "0.0" },
135975 => { address => "1.2.3.10", riskfactor => "1.0", riskscore => "0.0" },
137642 => { address => "1.2.3.11", riskfactor => "1.0", riskscore => "0.0" },
},
"site-id" => 27,
},
success => 1,
},
)
I want to loop through and print the devices and IPs associated with them and I for the life of me can’t come up with any code to do it. What the heck am I missing?! I tried to loop through a hash, a hash of hashes, etc. Can never get it to work. If any of you have a second and can provide an answer so I can shake my head in shame that’d be awesome.
I have tried:
foreach my $key (keys %{ $output->{‘SiteDevices’}->{‘device’} }) {
print $key
print $key->{‘address’}
}
and
foreach my $key (keys %{ $output{‘SiteDevices’}{‘device’} }) {
print $key
print $key{‘address’}
}
but neither works.