How do you write a perl script to determine the number of measurements, average, variance, standard deviation?
This is the script that I have so far and it is not working.
my @data = (6, 9, 7, 23, 30, 18);
my @data2 = (10, 5, 8, 11);
my @data3 = (12, 15, 13, 19, 5, 8, 10);
Data_info('Info',@data);
Data_info('Info',@data2);
Data_info('Info',@data3);
sub Data_info{
my($Data_info,@activity) = @_;
my ($num)=@Data_info +0;
my ($sum)=0;
my ($sqsum)=0;
foreach $x (@Data_info) {
$sum += $x;
$sqsum += $x * $x;
}
my ($avg)=$sum/$num;
my ($var)=$sqsum/$num-$avg*$avg;
my ($stand_dev)=sqrt ($var);
print "$Data_info:\n",
"Number of measurements = $num\n",
"Average = $avg\n",
"Variance = $var\n",
"Standard Deviation = $stand_dev\n\n";