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. :-)In reply to Re: Read in values and average -- Perl for MacOS X
by TedYoung
in thread Read in values and average -- Perl for MacOS X
by briglass
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |