in reply to Re^2: What defines the choice of a Hash or an Array?
in thread What defines the choice of a Hash or an Array?

That is correct, but its not as obvoious as you may think.

Among other things, realize that the space may be continous for array bodies or may not.
Also, as the hash keys are stored in a separate table, it depends on how long is the key, and of course, the length of the value for both hashes and arrays.

Some examples:

use Devel::Size qw(size); my @array; my %hash; my $array_size = size(\@array); my $hash_size = size(\%hash); print "Array: $array_size, Hash: $hash_size\n";
The hash allocates more memory in this case, and allocates more than the array in a lineal comparison for every filled key-value pair in the hash, and any contiguous index-value in the array.

On the other hand, you can try this:
use Devel::Size qw(size); use Data::Dumper; my @array; my %hash; $hash{'f'} = 140; $array[141] = 142; print Dumper @array; my $array_size = size(\@array); my $hash_size = size(\%hash); print "Array: $array_size, Hash: $hash_size\n";

Array indexes 0..141 are undefined, but some memory is reserved. In this case, for a single value a hash takes few memory.