Update: after reading jeffa's reply... if you wanted a hash slice, then my answer is a bit off...

That probably won't do what you thought it would... Try printing the contents of the has using Data::Dumper, and I think you will see:

use Data::Dumper; my %sample = ( [ 1, 2, 3, 4 ] => [ 5, 6, 7, 8 ] ); print Dumper( \%sample ); ==output== $VAR1 = { 'ARRAY(0x13c864)' => [ 5, 6, 7, 8 ] };

As you can see, hash keys are stringified. it does NOT hold the actual ref to an array...

The reason why your foreach loop works is because when you call keys(), you get the string values which are used as the hash keys... but you can't dereference them because they are just strings representing the arrayref's location in memory ( I think that's wht those hex numbers mean )

Anyway, the point is that in your code, $key is a string, not an arrayref. If you want to get to the array ref you have to do a bit more work


In reply to Re: Hash of refs to refs by lestrrat
in thread Hash of refs to refs by rje

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.