How to do sum of hash reference slice?
问题 I'm trying to get a sum of a hash reference slice, but I am failing #!/usr/bin/env perl use strict; use warnings FATAL => 'all'; use feature 'say'; use autodie ':all'; use List::Util 'sum'; my %h = ( 'a' => 1, 'b' => 2, 'c' => 3 ); my @letters = ('a','b'); say sum(@h{@letters}); # 1+2 = 3, which is correct my $h = \%h; # create a reference #say sum(@{ $h->{ @letters } }); # says "uninitialized value" #say sum(@{ $h }->{@letters}); # not an array reference say sum(@h->{@letters}); # @h