Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by japhy (Canon)
on May 15, 2001 at 03:36 UTC ( [id://80401]=note: print w/replies, xml ) Need Help??


in reply to How do I take a slice of a hash reference?

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://80401]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2025-06-18 02:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.