The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 -->
  #1 (permalink)  
Old 01-12-2008
cdfd123 cdfd123 is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 112
Post calculating variance in perl programming

#!/usr/bin/perl -w
use strict;


open(FH,"$ARGV[0]") or die;
my @temp=<FH>;
close FH;
my $mean = Mean(\@temp);
my $var = variance(\@temp);
print "$var\n";
sub estimate_variance {
my ($arrayref) = @_;
my ($mean,$result) = (mean($arrayref),0);
foreach (@$arrayref) { $result += ($_ - $mean)**2 }
return $result / $#{$arrayref};
}
error shown:
Undefined subroutine &main::variance called at variance_try1.pl line 9.

wht can be possible solution??

Last edited by cdfd123; 01-12-2008 at 10:47 AM.. Reason: correcting string