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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |