Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

( #80401=categorized answer: print w/ replies, xml ) Need Help??

Q&A > references > How do I take a slice of a hash reference? 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 };

Comment on Answer: How do I take a slice of a hash reference?
Select or Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-09-17 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (95 votes), past polls