in reply to Newbies question: initializing data structure
I'm not sure if the braces around the zero have any effect.
Then find it out:
use Data::Dumper; # your initialization code here print Dumper \%hash;
About your other questions:
$hash{"LISTS"}=[() x $length]
This doesn't do what you want, since you want really references to empty arrays, not empty lists (which get flattened out).
# WRONG $hash{"LISTS"}=[([]) x $length]
won't work either, because it returns many references to the same array.
A working solution is
$hash{LISTS} = [ map [], 1..$length ];
Though often this is not needed at all, thanks to autovivification. This works without error:
my %hash; # automatically creates $hash{LISTS} as an array ref, # and $hash{LISTS}[3] as an array ref: push @{$hash{LISTS}[3]}, 'new item'; # also works for direct assignment: $hash{LISTS}[4][0] = 'other new item';
|
|---|