in reply to Re: Hashes/Scalars and Memory Usage
in thread Hashes/Scalars and Memory Usage
The string in the array assignment is being interpreted in a numeric context, which makes it 0. Thus you are getting data from and assigning to index 0 of the array every time. The hash will grow, while the array will only contain the last item you save.use Data::Dumper; foreach (qw/ one two three /) { $hash{$_} = "in hash: $_"; $array[$_] = "in array: $_"; } print Dumper(\%hash, \@array); $VAR1 = { 'one' => 'in hash: one', 'three' => 'in hash: three', 'two' => 'in hash: two' }; $VAR2 = [ 'in array: three' ];
|
|---|