
Associative arrays and multi-dimensional arrays.
: $var1{$no}{$i} = $first;
: moreover, I not sure this is the way to do it. Perl dosen't cry on the
: syntax. But if it is, how do get my data again?
This is fine.
: I have tried something like this :
: foreach $key1 (sort keys (%var1)) {
this looks good, you don't need the sort unless you want
: foreach $key2 (keys %{$var1{$no}}) {
^^^ should be $key1
: $perhaps = $var1{$key1}{$key2}; # Here I go totally wrong
now you are fine
: but then I stopped, because I don't know how to address multi-assigned
You are RIGHT there .. just play around!
Check out perldsc and perllol in the latest documentation.
Here is a working example:
# initialize test hash
%hash = ( 'k1' => {'lev21k1' => 'value11', 'lev21k2' => 'value12'},
'k2' => {'lev22k1' => 'value21', 'lev22k2' => 'value22'}
);
# print out the values of the hash
foreach $key1 (keys %hash) {
foreach $key2 (keys %{$hash{$key1}}) {
print '$hash{', $key1, '}{', $key2, '} = ', $hash{$key1}{$key2}, "\n";
}
Quote:
}
This outputs:
$hash{k1}{lev21k1} = value11
$hash{k1}{lev21k2} = value12
$hash{k2}{lev22k2} = value22
$hash{k2}{lev22k1} = value21
hope this helps
MRK