#!c:\perl\bin\perl.exe -w use strict; use warnings; # This subroutine, given a set of values, should return the standard deviation. sub standard_deviation { my $mean = 0; my $sample_size; my @differences; for (@_) { $mean = $mean + $_; } $sample_size = scalar(@_); $mean = $mean/$sample_size; for (@_) { @differences = (@differences, (($_-$mean)*($_-$mean))); } my $standard = 0; for (@differences) { $standard = $standard + $_; } $standard = sqrt($standard/$sample_size); return $standard; } my $stddev; my @values; @values = (22, 17, 29, 39, 20, 32); $stddev = standard_deviation(@values); print "The standard deviation is $stddev.";