Reputation: 3843
I have a hash structure, where each key corresponds to a "value", which is an array. I defined and constructed this hash structure as follows:
my %app
push @{$app{$id}}, $id;
I am trying to make this hash structure to be indexed by another hash structure,
my %chainro
which itself is a hash of hash. It looks like there have three different approaches to connect these two structure, I am not sure which one is correct.
$chainro{$ro}{$id} = $app{$id}
@{$chainro{$ro}{$id}} = @{$app{$id}}
$chainro{$ro} = \%app;
Upvotes: 2
Views: 94
Reputation: 10786
The last one:
my %app
push @{$app{$id}}, $id;
$chainro{$ro} = \%app;
And you can then access an element:
$chainro{$ro}->{$id}->[$index]
The ->
are needed when you are accessing a hash or array using a reference rather than the hash or array itself.
Upvotes: 2