# 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 () { # open the file open F, $filename or die $!; my ($total, $count) = @_; while () { $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;