in reply to standard deviation help

For fun rather than for serious purpose, using the reduce function of the List::Utils module (or a home-made reduce function*) to build a library of statistical utilities in functional programming style.
sub sum { reduce { $a + $b } 0, @_; } sub avg { return undef unless @_; # avoid division by 0 sum (@_)/scalar @_; } sub variance { return undef unless @_; # avoid division by 0 my $avg = avg (@_); sum ( map {($_ - $avg)**2} @_ )/ scalar @_; } sub std_dev { sqrt variance (@_); }
The reduce utility can also be written in pure Perl:
sub reduce (&@) { my $code_ref = shift; my $result = shift; for (@_ ) { local ($a, $b) = ($result, $_ ); $result = $code_ref->($a, $b ) } return $result; }