in reply to Read in values and average -- Perl for MacOS X
Well, some examples of what you have tried and why it doesn't work would help us better understand what you need...
Here is some code to get you started:
# remember to use strict, warnings, etc open LOG, ">$logfile" or die $!; # You will need to update this: # go through each .txt file in DIR for my $file (<DIR/*.txt>) { # open the file open F, $filename or die $!; my ($total, $count) = @_; while (<F>) { $count ++; # the total number of samples $total += $_; # the running accumulator } close F; # remove the int if you want a decimal number. my $avg = int $total/$count; print LOG "$avg\n"; } close LOG;
Ted Young
($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
|
|---|