Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Statistic in Perl(Using Subroutines)

by jwkrahn (Monsignor)
on Jul 10, 2013 at 23:09 UTC ( #1043587=note: print w/ replies, xml ) Need Help??


in reply to Statistic in Perl(Using Subroutines)

sub average { @_ == 1 or die ('Sub usage: $average = average(\@array);'); my ($array_ref) = @_; my $sum; my $count = scalar @$array_ref; foreach (@$array_ref) { $sum += $_; } return $sum / $count; }
sub average { ref( my $array_ref = $_[ 0 ] ) eq 'ARRAY' or die 'Sub usage: $average = average(\@array);'; my $sum; $sum += $_ for @$array_ref; return $sum / @$array_ref; }


Comment on Re: Statistic in Perl(Using Subroutines)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2014-04-20 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls