in reply to Hash of a nArray and all that comes with it.
First of all, as it was pointed above, you should either create a reference to a hash (my $reference = { ... }) or just a hash (my %hash = ( ... )), note the brackets.
Next, contents of hash should be accessed using curly, not square brackets (the second is also possible because hashes can be treated as arrays). Example:
my %entry = ($item_id=>\@data, $item_id=>\@data); print $entry{$i}->[$j]; # contents of the hash ({}) are array referenc +es; we use -> to work with references; then we use [] to work with ar +rays # OR: my $reference = {$item_id=>\@data, $item_id=>\@data}; print $entry->{$i}->[$j]; # firstly, $entry is a reference to a hash, use -> # secondly, hash contents are accessed using {} # thirdly, it's again a reference # fourthly, arrays are accessed using []
Next, there is a special syntax to treat a variable as a reference: you can always use an array reference, in curly braces, in place of the name of an array. To get the index of an array by its reference, write $# and then write the reference in curly brackets:
my $index = $#{$entry{$i}};
See perlreftut for more.
|
|---|