in reply to Dereferencing a Hash of Arrays

values returns two individual array references, which you can't dereference in one go. You have to iterate over them:

for my $aref (values %alphabet) { say for @$aref; }

Also, you probably meant to take references of the arrays only, not of every element used to initialize the hash.   \( ... ) takes references of every element of the (unflattened!) list, so the resulting data structure is

... use Data::Dumper; print Dumper \%alphabet;
$VAR1 = { 'SCALAR(0x783790)' => [ '1', '2', '3', '4' ], 'SCALAR(0x783e50)' => [ '9', '8', '7', '6' ] };

which is probably not what you intended. (The scalar refs are stringified here, because hash keys are always strings in Perl.)

Replies are listed 'Best First'.
Re^2: Dereferencing a Hash of Arrays
by toro (Beadle) on Jun 14, 2011 at 07:24 UTC

    Hmm ... so why does this work?

    my @idontgetit = values %alphabet; say for @idontgetit->[0]->[0];

    (It doesn't "work" in the sense of printing out what's desired but it does print out part of what's desired.)

      @idontgetit holds the two array refs. @idontgetit->[0] indexes the first one of it, and the second ->[0] indexes the first element of the (inner) array.

      BTW, @idontgetit->[0]->[0] should better be written as $idontgetit[0]->[0]   (turn on warnings, and Perl will tell you why).

        I saw that warning before (I try to crack these nuts for a few hours before I ask the monks). I failed with $idontgetit->[0]->[0] and just went back to the @ syntax since it printed anything. Sometimes Perl forgives my syntax, sometimes not.