The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 01-12-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,938
It might be easier if you used a standard proven statistics module of which there are a number on CPAN.

For example, I have modified your code to work with the CPAN Module Statistics/Descriptive


Code:
#!/usr/local/bin/perl -w

use strict;
use Statistics::Descriptive;

open(FH, "$ARGV[0]") or die "No file specified\n";
my @temp=<FH>;
close FH;

my $stat = Statistics::Descriptive::Full->new();
$stat->add_data(\@temp);
my $mean = $stat->mean();
my $variance  = $stat->variance();
my $num  = $stat->count();

print "Number of Values = $num\n",
      "Mean             = $mean\n",
      "Variance         = $variance\n";