Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Answer: How do I take a slice of a hash reference?

by japhy (Canon)
on May 15, 2001 at 03:36 UTC ( #80401=categorized answer: print w/replies, xml ) Need Help??

Q&A > references > How do I take a slice of a hash reference? - Answer contributed by japhy

Here's how:
@slice = @{$array_ref}[ @idx ]; @slice = @{$hash_ref}{ @keys };
And there's no easy way to "pretend" a list is a hash. You need to use a hash reference explicitly:
$scalar = {1, 'a', 2, 'b'}->{$key}; @slice = @{ { 1, 'a', 2, 'b' } }{ @keys };

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[choroba]: Monopoli looks nice, but a bit far from here.
[1nickt]: Morning monks, howzit?

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2018-01-23 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (246 votes). Check out past polls.

    Notices?