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

Re^2: get the average of hash values?

by k_manimuthu (Monk)
on Jul 28, 2010 at 08:29 UTC ( #851684=note: print w/ replies, xml ) Need Help??


in reply to Re: get the average of hash values?
in thread get the average of hash values?

You May use the 'List::Util' module for this task.

use strict; use warnings; use List::Util('sum'); ## Store the hash value my %hash = ( 'A' => 46, 'D' => 18, 'C' => 17, 'B' => 31 ); ## values %hash -> gives the values of the hash ## keys %hash -> get number of element in this hash my $sum = sum (values %hash)/keys %hash; print $sum;


Comment on Re^2: get the average of hash values?
Download Code
Re^3: get the average of hash values?
by JavaFan (Canon) on Jul 28, 2010 at 08:48 UTC
    I don't understand. The OP wants an average for each of 'A', 'B', 'C', 'D' (four numbers). Your input (%hash) doesn't have the information to do that, and your output (a ratio, called '$sum') is a single number.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2015-07-06 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls