$hash{$id} = (1,2,3); will set $hash{$id} = 3 (the last element in the list).
and $hash{$id} = @temp; will set $hash{$id} = 3 (the length of @temp).
You cannot literally make a hash with arrays as the values in Perl, you need array-references:
Note that \(1,2,3) will make a list of references to 1, 2 and 3, so don't use that.$hash{$id} = [1,2,3]; # [ ... ] creates an anonymous array ref @temp = (1,2,3); $hash{$id} = \@temp; # \ makes an explicit reference to @temp
If you want to read one of the values from the array ref you do:
$x = ${$hash{$id}}[0]; # or $x = $hash{$id}[0]; # or $x = $hash{$id}->[0];
I like the last syntax best, because it makes it clear that there is a reference (more or less equivalent to a "pointer" in C speak) involved.
If you want to whole list of values from the array, you can do:
perlref has a lot of info about this.my @values = @{$hash{$id}};
In reply to Re: Regarding Hashes of Arrays
by Joost
in thread Regarding Hashes of Arrays
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |