Hash keys are stringified, and thus, references can't be hash keys. If you place a reference in a hash key it gets stringified to something like "ARRAY 0x3E0CFF", and can't be resurrected.
Are you looking for a hash slice?
my %hash; @hash{ 'A', 'B', 'C' } = ( 1, 2, 3 );
Incidentally (and a bit off your original topic), the fact that references stringify when used as hash keys -- including blessed refs -- is the basis for keeping track of inside-out objects:
package InOut; use strict; use warnings; my %instances; sub new { my( $class, @params ) = @_; my $obj = bless {}, $class; $instances{$obj} = { params => [ @params ]}; return $obj; } sub getparam { my ( $self, $index ) = @_; return $instances{$self}{params}[$index]; } 1; package main; use strict; use warnings; my $thingy = InOut->new(qw/ Bart Homer Marge Maggie Lisa / ); print $thingy->getparam( 2 ), "\n";
Dave
In reply to Re: HoHoA with anonymous array refs as the key to access the A
by davido
in thread HoHoA with anonymous array refs as the key to access the A
by Grygonos
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |