Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

n3toy's scratchpad

by n3toy (Hermit)
on Aug 07, 2008 at 22:04 UTC ( #703013=scratchpad: print w/replies, xml ) Need Help??

n3toy: I have a hash where the values are all numerical. Is there a quick way to sum all the hash values?

GrandFather: my $total; $total += $_ for values %hash;

Lawliet: $sum += $hash{$_} foreach keys %hash;

tye: my $count= map( (1)x$_, values %hash );

Lawliet forgot there was a values keyword!

davido: use List::Util qw(sum); my $total = sum( values %hash );

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
Discipulus 3 earthquake between 5.1 and 5.3.. Closed the subway in roma and many schools evacuated: the school of my little daugther was evacuated.. but nobody called us..

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2017-01-18 11:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (161 votes). Check out past polls.