in reply to Code Review! Go Ahead, Rip It Up!

Here you go. This one's free! ;)
sub standard_deviation { # declared all at once my ($mean, $std_dev) = (0,0); # idioms are handy -- I like the postfix 'for' # and '$x = $x + $y' can be written as '$x += $y' $mean += $_ for @_; # no need for $size, it's used once, and is @_ # again, using the 'A = A OP B' => 'A OP= B' trick $mean /= @_; # appending to arrays is best done with push() # @big_array = (@big_array, $x) can get slow :( # for (@_) { # push @diffs, ($_ - $mean)**2; # } # that can be rewritten as a map() # @diffs = map { ($_ - $mean)**2 } @_; # but we only use @diffs ONCE, so we don't need it $std_dev += ($_ - $mean)**2 for @_; # and $size was removed, so we use @_ again return $std_dev / @_; }
When it comes down to it, the function becomes:
sub standard_deviation { my ($mean, $std_dev) = (0,0); $mean += $_ for @_; $mean /= @_; $std_dev += ($_ - $mean)**2 for @_; return $std_dev / @_; }

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;