Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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;

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://851684]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2017-04-29 08:36 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (531 votes). Check out past polls.