Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Fetch array of values from hashref

by AnomalousMonk (Archbishop)
on Sep 10, 2019 at 14:46 UTC ( [id://11105970]=note: print w/replies, xml ) Need Help??


in reply to Fetch array of values from hashref

c:\@Work\Perl\monks>perl -wMstrict -MData::Dumper -le "my @a = qw/c b d/; ;; my %h = ( a => 4, b => 3, c => 2, d => 1, ); ;; my @b = @h{@a}; print \"2 3 1\n\", Dumper(\@b), \"\n\"; ;; my $hr = \%h; my @c = @{ $hr }{ @a }; print \"2 3 1\n\", Dumper(\@c), \"\n\"; " 2 3 1 $VAR1 = [ 2, 3, 1 ]; 2 3 1 $VAR1 = [ 2, 3, 1 ];

Update: Oops... Fixed example code: Was dumping  @b twice!


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11105970]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2026-05-11 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.