Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Fetch array of values from hashref

by AnomalousMonk (Bishop)
on Sep 10, 2019 at 14:46 UTC ( #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
Node Status?
node history
Node Type: note [id://11105970]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2019-10-17 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?