in reply to Re: Read in values and average -- Perl for MacOS X
in thread Read in values and average -- Perl for MacOS X

sh1tn-

Thanks for the code-- It seems to work perfectly, except for the fact that the resulting mean value seems to be (sum * count) instead of (sum / count). I tried fiddling with the code to get it to output the ratio instead of the product, but to no avail.

For example, a file with the following comma delimited values:

1 1 1

outputs:

9

(1+1+1 * 3)

Any ideas?

Thanks,
Brian

  • Comment on Re^2: Read in values and average -- Perl for MacOS X

Replies are listed 'Best First'.
Re^3: Read in values and average -- Perl for MacOS X
by sh1tn (Priest) on Feb 15, 2005 at 09:02 UTC
    Please, excuse my lack ot attention.
    my @files; my (@l_count, $l_count); my (@f_count, $f_count); my @all; my $res_file = 'end_res.log'; -f $res_file and unlink $res_file; grep{ -f and push @files, $_ }glob '*'; for( @files ){ open FH, $_ or die $!; while( <FH> ){ /(?:\d+\s*\d*)/ or next; push @l_count, $_ for split '\s+', $_; $l_count += $_ for @l_count; push @f_count, ( $l_count / ($#l_count + 1) ); $l_count = 0; @l_count = (); } close FH; $f_count += $_ for @f_count; push @all, ( $f_count / ($#f_count + 1) ); $f_count = 0; @f_count = (); } open FH, ">$res_file" or die $!; print FH $_, $/ for @all; close FH;