I m still in here. ;)
I ve got this code from a very expert guy, and I m shy to ask him this basic questions...anyway this is my question now; this Perl Script prints the median of a column of numbers delimited space, and, I added some stuff to get the size of it, now I m trying to get the sum of the same column. I did and got not results, did I not take the right column? ./stats.pl 1 columns.txt
#!/usr/bin/perl
use strict;
use warnings;
my $index = shift;
my $filename = shift;
my $columns = [];
open (my $fh, "<", $filename) or die "Unable to open $filename for reading
";
for my $row (<$fh>) {
my @vals = split/s+/, $row;
push @{$columns->[$_]}, $vals[$_] for 0 .. $#vals;
}
close $fh;
my @column = sort {$a <=> $b} @{$columns->[$index]};
my $offset = int($#column / 2);
my $length = 2 - @column % 2;
my @medians = splice(@column, $offset, $length);
my $median;
$median += $_ for @medians;
$median /= @medians;
print "MEDIAN = $median
";
################################################
my @elements = @{$columns->[$index]};
my $size = @elements;
print "SIZE = $size
";
exit 0;
#################################################
my $sum = @{$columns->[$index]};
for (my $size=0; $size < $sum; $size++) {
my $mean = $sum/$size;
};
print "$mean
";
预先感谢。