Hey All:
I have this script here to calculate the average and standard deviation of a
bunch of numbers in a text file. For some reason, it doesn't seem to go
through the second while loop at all. Am I doing something wrong? Please
help!!!
#!/usr/bin/perl
use strict;
use warnings;
my $year4 = 1997;
my $year2 = '97';
chdir "/home/kfevans/grbs/$year4/bkgd" or die "Can't open $year4/bkgd:
$!\n";
open(FILE, ">/home/kfevans/grbs/$year4/bkgd/avg_stdev_$year2.txt") or die
"Can't open FILE: $!\n";
foreach my $file (<*.bkgd.txt>) {
$file =~ /^(\d+)\.bkgd\.txt/;
my $num = $1;
my $value1 = 0;
my $value2 = 0;
my $count = 0;
open(F, $file);
while (<F>) {
$value1 += $_;
$count++;
}
close F;
my $avg = $value1 / ($count -1);
open(T, $file);
while (<T>) {
my $dev = ($_ - $avg)**2;
my $value2 += $dev;
}
close T;
my $stdev = sqrt ($value2 / ($count - 2));
print FILE "$num $avg $stdev\n";
print STDOUT "$num $avg $stdev\n";
}
Kind regards,
Kenny
***********************************************************
Kenneth Evans Jr.
Physics B.S. Candidate
ASI Science Senator 04-05
www.amanda.wisc.edu/kfevans
California State Polytechnic University, Pomona
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs