Hey,
first, I did not test the code, second I know this can be accomplished much shorter. Actually, I'm thinking about a oneliner.
Nevertheless, you are a newby and I suggest this code since it is much more readable.
#!/usr/bin/perl my %data; opendir( DIR, "input/*" ); while( my $file = readdir( DIR )) { open( FILE, $file ); while ($line = <FILE>) { chomp( $line ); $data { $file } -> { sum } += $line; $data { $file } -> { count } ++; } close( FILE ); } closedir( DIR ); open( FILE, ">", "result.txt" ); foreach my $file (sort keys %data) { printf FILE "%1.2f\n", $data { $file } -> { sum } / $data { $file +} -> { count }; } close( FILE );
In reply to Re: Read in values and average -- Perl for MacOS X
by m-rau
in thread Read in values and average -- Perl for MacOS X
by briglass
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |