THANK YOU EVERYONE FOR THE GREAT REPLIES. I must go commune with myself now since it's truly perplexing when one must derefernece and when not to, and when the dereference is implicit.

==========

original question Below:

Commonly one can index out multiple keys simultaneously from a hash like this:

my (%H) = (1,100,2,200,3,300); @A= @H{ (1,3) };

@A now contains (100,200)

But how do I do this when I have not the Hash itself but a reference to the hash?

I want to be able to write something like this:

my $Href = {1 => 100,3 =>300}; @A = @{$Href}->{ (1,3) };

But that does not work.

It would be crazy to reconsitutute the hash (if the hash is enormous) so I don't consider the following a viable option:

$Href = {1 => 100,3 =>300}; %H = %{$Href}; @A = @H{ (1,3) };

The following does work but it is a hideous kludge I think should not be neccessary:

$Href = {1 => 100,3 =>300}; my @A; { local %G; *G = $Href; @A = @G->{ (1,3) } }

Yuck...

SO what's the right way to slice index a a hash reference?

Code tags added by GrandFather


In reply to Looking up an array of keys with a Hash reference by cems22

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.