$h{2} isn't a reference to $h{1}. $h{2} is a reference to the same array that $h{1} refers to.
I think you probably want:
for my $i ( 1 .. 2 ) { my @new = @a; # copy of @a $h{"$i"} = \@new; # reference the copy }
Or (more concise way of saying the same thing)...
for my $i ( 1 .. 2 ) { $h{"$i"} = [@a]; }
In reply to Re: help with references
by tobyink
in thread help with references
by dw_perlmonks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |