I have what I believe to be a Hash that references an array of hashes. What I am trying to understand is how to access the hash elements within this array of hashes.
EDIT: Here is the full hash structure
$VAR1 = {
'CVE-2015-0677' => {
'vuln:references' => [
{
'attr' => {
'reference_type' => 'VENDOR_ADVISORY',
'xml:lang' => 'en'
},
'vuln:source' => 'CISCO',
'vuln:reference' => [
{
'attr' => {
'href' => 'http://tools.cisco.com/security/center/content/CiscoSecurityAdvisory/cisco-sa-20150408-asa',
'xml:lang' => 'en'
}
}
]
}
],
'vuln:published-datetime' => '2015-04-12T21:59:03.033-04:00',
'vuln:last-modified-datetime' => '2015-04-13T17:45:18.310-04:00',
'vuln:vulnerable-software-list' => [
'cpe:/o:cisco:adaptive_security_appliance_software:9.0.3',
'cpe:/o:cisco:adaptive_security_appliance_software:8.4.5',
],
'vuln:summary' => 'The XML parser in Cisco Adaptive Security Appliance (ASA) Software 8.4 before 8.4(7.28), 8.6 before 8.6(1.17), 9.0 before 9.0(4.33), 9.1 before 9.1(6), 9.2 before 9.2(3.4), and 9.3 before 9.3(3), when Clientless SSL VPN, AnyConnect SSL VPN, or AnyConnect IKEv2 VPN is used, allows remote attackers to cause a denial of service (VPN outage or device reload) via a crafted XML document, aka Bug ID CSCus95290.'
}
};
If I try the following the output of the first Data::Dumper output is identical to the second.
for my $key ( keys $hash ) {
my @references = $hash->{$key}{'vuln:references'};
print Dumper(@references); #1
for my $vulnref (@references) {
print Dumper($vulnref); #2
}
}
#1
$VAR1 = [
{
'vuln:reference' => 'VENDOR',
'vuln:source' => 'CISCO',
}
];
#2
$VAR1 = [
{
'vuln:reference' => 'VENDOR',
'vuln:source' => 'CISCO',
}
];
So my for loop doesn't seem to be having any affect?
However if I loop through twice then the second loop
for my $key ( keys $hash ) {
my @references = $hash->{$key}{'vuln:references'};
print Dumper(@references); #1
for my $vulnref (@references) {
for my $vuln ($vulnref) {
print Dumper($vuln); #2
}
}
}
#1
$VAR1 = [
{
'vuln:reference' => 'VENDOR',
'vuln:source' => 'CISCO',
}
];
#2
$VAR1 = {
'vuln:reference' => 'VENDOR',
'vuln:source' => 'CISCO',
};
I now seem to be accessing the hash.
I believe I am missing something fundamental here.
Many thanks.
print Dumper $hash.