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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.