This about using numbers as hash keys. It doesn't answer the question directly as it doesn't compare the facilities that arrays provide, but I thought it would be a good place to put the information.
Suppose a hash with ten elements is built using code like this
use strict;
use warnings;
my %hash;
my $n = 1000;
for (1 .. 10) {
$hash{$n} = 1;
$n *= 1000;
}
and then we query it, looking for keys that are powers of ten. Of course the easiest way to multiply an integer by ten is to add a zero, so it is fine to write
my $m = '1';
for (1 .. 100) {
print $m, "\n" if $hash{$m};
$m .= 0;
}
which has the output
1000
1000000
1000000000
1000000000000
1000000000000000
1000000000000000000
We entered ten elements but this shows only six. What has happened? Let's take a look at what's in the hash.
use Data::Dump;
dd \%hash;
and this outputs
{
"1000" => 1,
"1000000" => 1,
"1000000000" => 1,
"1000000000000" => 1,
"1000000000000000" => 1,
"1000000000000000000" => 1,
"1e+021" => 1,
"1e+024" => 1,
"1e+027" => 1,
"1e+030" => 1,
}
so the hash doesn't use the keys that we imagined. It stringifies the numbers in a way that it would be foolish to try to emulate.
For a slightly more practical example, say we had some circles and wanted to collect into sets by area. The obvious thing is to use the area as a hash key, like this program which creates 100,000 circles with random integer diameters up to 18 million.
use strict;
use warnings;
use 5.010;
package Circle;
use Math::Trig 'pi';
sub new {
my $class = shift;
my $self = { radius => shift };
bless $self, $class;
}
sub area {
my $self = shift;
my $radius = $self->{radius};
pi * $radius * $radius;
}
package main;
my %circles;
for (1 .. 100_000) {
my $circle = Circle->new(int rand 18_000_000);
push @{ $circles{$circle->area} }, $circle;
}
Now let's see how many of those hash keys use scientific notation
say scalar grep /e/, keys %circles;
which says (randomly, of course)
861
so there really isn't a tidy way of know what string perl will use if we specify a number as a hash index.