Dear all,
Thank for replying my post. Here is the summary of all
the posssible code lines:
Q:If Perl has the short-cut/built-in function for
calculating Mean/Average?
my @data=(1,1,1);
mean/average=(1+1+1)/3=1;
A:
No Perl built-in function for mean/average but there
are several ways to do it:
1) my $mean = do { my $s; $s += $_ for @data; $s /
@data };
2)List::Util is "built-in" as of 5.8, and back
compatible to 5.5
use List::Util qw(sum);
my $average = sum(@input) / @input;
3) my $mean= (map$a+=$_/@data,@data)[-1];
4)my $mean = do { my $s; $s += $_ for @data; $s /
@data };
5) my $mean+=$_/@data [EMAIL PROTECTED];
6)$mean = eval(join("+", @data)) / @data;
Depending on how you understand Perl and what progress
you are I prefer 6).
Li
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>