So I am trying to use a Perl HoH and push some values into an array from the HoH.
Here is a portion of the code to better explain;
my $hoh = (
antenna_included=>{
"1" => '1 MultiBand Antenna',
"2" =>'2 Multiband Antennas',
"3" =>'1 MultiBand Antenna & 2 WiFi Antennas',
"4" =>'2 Multiband Cellular Antennas & 2 WiFi Antennas',
"N" =>'No Antennas Included',
},
ip_rating=>{
I6 => 'IP 64',
CD => 'Intrinsically Safe, Class 1 Div 2, IP 64',
NI => 'No',
});
foreach $group ( sort keys %hoh ) {
foreach $spec ( sort keys %{ $hoh{$group} } ) {
print "$spec=>$hoh{$group}{$spec}\n";
}
print "what part is it: ";
my $input = <STDIN>;
chomp $input;
if ( exists $hoh{$group} ) {
print "$hoh{$spec}\n"; #this is the problematic line.
}
else {
print "not a match!\n";
}
}
Basically the goal of this script is to loop through the HoH, but throughout each block of hash it gives STDIN
, then you type in the key
, and then then I want to push the value
of that element into an array. (Right now the code just says print
for debugging).
I have tried
$hoh{$group}{$spec}
$hoh{$group}
$hoh{$group}->{$spec}
For $hoh{$group}
I get HASH(0x6ff920)
and all of the other values it is just blank, no error.
Any thoughts? Thank you