I want to use an array for the keys of a hash, and I want that array to point at another array as the values in the hash, something like the following:
my @multiKey1 = ("a","b"); my @stuff1 = ("1", "2", "3"); my @multiKey2 = ("c","d"); my @stuff2 = ("4", "5"); my @multiKey3 = ("e","f"); my @stuff3 = ("6", "7"); my %testHash = ( \@multiKey1 => \@stuff1, \@multiKey2 => \@stuff2, \@m +ultiKey3 => \@stuff3);
The problem right now is, although I can get access to the arrays again if I access a specific value with a specific key, I can't get access when I just try keys() to start out. E.g.
@testHashKeys = keys %testHash; @testHashValues = values %testHash; $tmp = @testHashKeys; foreach (@testHashKeys){ print "deref bla = @$_ = $_\n"; } foreach (@testHashValues){ print "deref bla = @$_ = $_\n"; } $ref = $testHash{$testHashKeys[0]}; @valueArray = @$ref; print "valueArray = @valueArray\n";
For this, I get the following output, and I don't understand why :-/
deref bla = = ARRAY(0x10082add0) deref bla = = ARRAY(0x10082afc8) deref bla = = ARRAY(0x10082aed8) deref bla = 1 2 3 = ARRAY(0x10082ae48) deref bla = 6 7 = ARRAY(0x10082b040) deref bla = 4 5 = ARRAY(0x10082af50) valueArray = 1 2 3
The key thing is the line: print "deref bla = @$_ = $_\n"; If it knows that $_ is an array reference, why doesn't @$_ dereference it to give me the array values printed out, like everywhere says it should, and like happens with the values array? I greatly appreciate you taking the time to read this :)

In reply to reference as hash keys and values by ChangeManagement

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.