in reply to Arrays as Hash Values

I'm going to take a stab and say that you misunderstood the Categorized Questions and Answers node. It's not that you use the arrayref itself as the key, but that the value is an arrayref. So, you would have something like:
my %hash = ( key1 => [1, 2, 3], key2 => [5, 6, 7], );
Then, when you wanted to get the values back, you'd do something like $hash{key1}[2] and that would give you 3.

The problem with using an arrayref as a hashkey is that the reference gets stringified. That process ends up being divorced from the actual reference, meaning you can't get to it from the key itself.

------
/me wants to be the brightest bulb in the chandelier!

Vote paco for President!

Replies are listed 'Best First'.
Re: Re: Arrays as Hash Values
by c (Hermit) on Aug 16, 2001 at 03:11 UTC
    Yes, I hear/see what you are saying, however, what if my array elements need to be interpolated:

    my %hash = ( key1 => ["one thing","one $thing","$another"], key2 => ["and the list","keeps $going"] );

    When I go down this road, I am seeing errors. Should I be? or is this syntax correct? Apologies for not getting into this prior.

    humbly -c

      As far as I can tell, that syntax looks to be just fine. What I would do at this point is to post an actual running script (doesn't have to be long) and its output, including errors. That way, we can help you more.

      ------
      /me wants to be the brightest bulb in the chandelier!

      Vote paco for President!

      try enclosing key1 and key2 in quotes