%HoH = (
Group1=> {
member1=> "fred",
member2=> "barney",
},
Group2 => {
member1 => "george",
member2 => "jane",
},
);
How can I access second value or second key of HoH I want to access member2 of each group keys and their associated values.I don’t know my key name , I just know it is second key
foreach $key (keys %HoH){
foreach $value (keys %{$HoH{$key}}){
print $key."\n";
}
}
You cannot access neither “second key” nor “second value” because there’s no particular order of hash elements.
print Dumper(\%HoH);will likely give you another order of hash elements than the order you initializer used. You should use hash of arrays if you want a particular order.After that you can access “fred” as
$HoH{Group1}->[0]and “jane” as$HoH{Group2}->[1].