in reply to Mean, Median and Mode

I presume(perhaps wrongly) that you mean something like the following:

#!/usr/bin/perl -w use strict; use warnings; sub mean { my (@data) = @_; my $sum; foreach (@data) { $sum += $_; } return ( $sum / @data ); } sub median { my (@data) = sort { $a <=> $b } @_; if ( scalar(@data) % 2 ) { return ( $data[ @data / 2 ] ); } else { my ( $upper, $lower ); $lower = $data[ @data / 2 ]; $upper = $data[ @data / 2 - 1 ]; return ( mean( $lower, $upper ) ); } } sub std_dev { my (@data) = @_; my ( $sq_dev_sum, $avg ) = ( 0, 0 ); $avg = mean(@data); foreach my $elem (@data) { $sq_dev_sum += ( $avg - $elem )**2; } return ( sqrt( $sq_dev_sum / ( @data - 1 ) ) ); } my ( $data, @dataset,%h,$lc ); my $file = "fake.txt"; open(IN, "<", $file) or die "can't open $file $!\n"; while (<IN>) { chomp; $lc++; $h{$lc} = $_; } close IN; #while (<DATA>) { # chomp; # $lc++; # $h{$lc} = $_; #} #@dataset = (values %h); print "vals " .scalar(keys %h) . "\n"; print "Median: ", median(@dataset), "\n"; print "Mean: ", mean(@dataset), "\n"; print "Standard Dev.: ", std_dev(@dataset), "\n"; __DATA__ 1 4 2 7 89 5 2 8 6 23

If this assignment actually requires you to process the data in the subs by handing in the hash instead of the array, you should find enough here to get you started... . Run it with 'perl -d' to see what things look like. The debugger is easy to use.

One also has to presume that 'fake.txt' looks like __DATA__, which you did not specify.

...the majority is always wrong, and always the last to know about it...

Insanity: Doing the same thing over and over again and expecting different results...

A solution is nothing more than a clearly stated problem...otherwise, the problem is not a problem, it is a facct