pme has asked for the wisdom of the Perl Monks concerning the following question:
Could you tell me how can I fetch array of values from hashref in single instruction? Thanks.
my @a = qw/c b d/; my %h = ( a => 4, b => 3, c => 2, d => 1, ); my @b = @h{@a}; # this one works as expected print "2 3 1\n", Dumper(\@b), "\n"; my $h = \%h; my @c = @{%$h}->{@a}; # this one fails, what is the correct syntax? print "2 3 1\n", Dumper(\@c), "\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Fetch array of values from hashref
by AnomalousMonk (Archbishop) on Sep 10, 2019 at 14:46 UTC | |
Re: Fetch array of values from hashref
by Eily (Monsignor) on Sep 10, 2019 at 15:27 UTC | |
Re: Fetch array of values from hashref
by LanX (Saint) on Sep 10, 2019 at 16:28 UTC | |
Re: Fetch array of values from hashref
by k-mx (Scribe) on Sep 11, 2019 at 07:30 UTC | |
by haukex (Archbishop) on Sep 11, 2019 at 07:39 UTC | |
by AnomalousMonk (Archbishop) on Sep 11, 2019 at 15:36 UTC | |
by k-mx (Scribe) on Sep 11, 2019 at 16:30 UTC | |
Re: Fetch array of values from hashref
by pme (Monsignor) on Sep 10, 2019 at 20:29 UTC |