in reply to Re^3: seeking advise on average value problem
in thread seeking advise on average value problem

This is the form that I ended using in the end. In addition to the average I also had values that needed to be totaled. One of the problems I ran into was if I didn't close the file before I started the new hash it wouldn't pick any values. I'm not sure if thats a to be expected part or inexperience. thanks all.
#!/usr/bin/perl open( FILE, "process.log") or die "Can't open average.txt : $!"; while (<FILE>) { next unless ( /(\w+)_mean_time:\s+([\d.]+)/ ); $stats{$1}{count}++; $stats{$1}{sum} += $2; } printf( "%20s %5s %8s\n", "Name", "hours", "Average" ); for ( sort keys %stats ) { printf( "%19s: %5d %8.2f\n", $_, $stats{$_}{count}, $stats{$_}{sum} / $stats{$_}{count} ); } close(FILE); open( FILE, "process.log") or die "Can't open average.txt : $!"; while (<FILE>) { next unless ( /(\w+)_total_counts:\s+(\d+)/ ); $counter{$1}{count}++; $counter{$1}{sum} += $2 } printf( "%20s %5s %8s\n", "Name", "hours", "total" ); for ( sort keys %counter ) { printf( "%19s: %5d %8.2f\n", $_, $counter{$_}{count}, $counter{$_}{sum} ); } close(FILE);