Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 exploiting the Monastery: (7)
As of 2014-09-23 08:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (212 votes), past polls