use strict; sub put { my ($hash_ref, $main_key, $sub_key, $value) = @_; if (!exists($hash_ref->{$main_key})) { $hash_ref->{$main_key} = {}; } $hash_ref->{$main_key}->{$sub_key} = $value; } sub display { my $hash_ref = shift; my ($main_key, $sub_key); foreach $main_key (keys %{$hash_ref}) { foreach $sub_key (keys %{$hash_ref->{$main_key}}) { print "{$main_key, $sub_key} = " . $hash_ref->{$main_key}- +>{$sub_key}, "\n"; } } } my $hash_ref = {}; put($hash_ref, "one", "key1", "value1"); put($hash_ref, "one", "key2", "value2"); put($hash_ref, "two", "key1", "value1"); put($hash_ref, "two", "key3", "value3"); display($hash_ref);
In reply to Re: Adding additional values to a hash of an hash ?
by Anonymous Monk
in thread Adding additional values to a hash of an hash ?
by gnangia
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |