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??

variance () is not a Perl function. You will need to write your own or find a module that can do it.

I though you were trying to do this in C :confused:

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

#!/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";

Dear Shamrock
I have tried both using c and perl ..
So got results both in C and perl..
Thanks for curiosity