%a = ( "KEY" => {
"p1" => 1 , [1223],
"p1" => 2 , [2323],
"p1" => 3 , [2353],
}
);
I want to generate a structure like this. I have tried with this code:
@array = ( 1223 , 2323 ,2353 );
$count = 0;
foreach my $i (@array) {
$a{"KEY"} => { "p1" => $count , [$i] };
$count++;
}
How can I create such a hash?
The above data structure cannot be realised as hashes can have unique keys only. You should replace the value of the key
KEYto an ARRAYREF instead of a HASHREF.The following program seems to do what you want by using ARRAYREFs.