in reply to Re^4: non-scalar hash key
in thread non-scalar hash key
The problem with your suggestion is that two arrays with the same elements will give two entries in the hash (because they will have different references). Consider:
use strict; use warnings; use Data::Dumper; my @foo = qw/1 2 3 4 5 6/; my @fu = qw/1 2 3 4 5 6/; my %bar = ( \@foo => 'elephants', \@fu => 'zebras' ); print Dumper \%bar;
Outputs something like:
$VAR1 = { 'ARRAY(0x18ae770)' => 'zebras', 'ARRAY(0x17f0ec8)' => 'elephants' };
And:
my @foo = qw/1 2 3 4 5 6/; my @fu = qw/1 2 3 4 5 6/; my %bar = ( join ('',@foo) => 'elephants', join ('',@fu) => 'zebras' ); print Dumper \%bar;
Outputs:
$VAR1 = { '123456' => 'zebras' };
citromatik
In Section
Seekers of Perl Wisdom