perl自带的标准差模块确实难用,找了个这个:
http://andrewstechhints.blogspot.com/2010/02/standard-deviation-in-perl.html
#!/usr/bin/perl use strict; use warnings; my @my_array = (1,6,9,2,5,12,1); my $average = average(@my_array); my $std_dev = std_dev($average, @my_array); printf "avg=%.2f, st. dev=%.2f ", $average, $std_dev; sub average { my (@values) = @_; my $count = scalar @values; my $total = 0; $total += $_ for @values; return $count ? $total / $count : 0; } sub std_dev { my ($average, @values) = @_; my $count = scalar @values; my $std_dev_sum = 0; $std_dev_sum += ($_ - $average) ** 2 for @values; return $count ? sqrt($std_dev_sum / $count) : 0; }