HASH OF HASH Flashcards
1
Q
DECLARE HASH OF HASH
A
%hash = (
‘key’ => { ‘sub_key’ => ‘value}, …);
2
Q
LOOP THROUGH HASH OF HASH
A
for my $i (sort(keys %hash)) {
print $i;
for my $j (sort(keys %hash{$i})) {
print “$j:” %hash{$i}{$j};
}
}
3
Q
CHECK INDIVIDUAL VALUE OF HASH OF HASH
A
$value = $hash{‘key’}{‘subkey’};
4
Q
CHECK INDIVIDUAL VALUE OF HASH OF HASH
A
$value = $hash{‘key’}{‘subkey’};
5
Q
ADD KEY VALUE PAIR
A
$hash{‘key’}{‘newksubkey’} = ‘newvalue’;
6
Q
DELETE SUBKEY
A
delete $hash{‘key’}{‘subkey’};
7
Q
UPDATE VALUE
A
$hash{‘key’}{‘subkeytobeupdated’} = ‘updatedvalue’;
8
Q
IF EXISTS KEY
A
if (exists $hash{‘key’}){
#statement
}
9
Q
IF EXISTS SUBKEY
A
if (exists $hash{‘key’}{‘subkey’}){
#statement
}