Created
January 30, 2011 05:38
-
-
Save ytnobody/802589 to your computer and use it in GitHub Desktop.
hogehoge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use warnings; | |
use strict; | |
my $file = 'file.dat'; | |
my $data = {}; | |
open my $fh, '<', $file or die "Couldn't open file"; | |
while ( my $line = <$fh> ) { | |
$line =~ s/(\r\n|\n)$//; | |
my ( $key, $val ) = $line =~ /^(.+)=(.+)$/; | |
$data->{ $key } ||= { sum => 0, count => 0 }; | |
$data->{ $key }->{ sum } += $val; | |
$data->{ $key }->{ count } ++; | |
} | |
close $fh; | |
print join( "\t", qw/ name sum count average / )."\n"; | |
for my $key ( sort keys %$data ) { | |
print join( "\t", $key, $data->{ $key }->{ sum }, $data->{ $key }->{ count }, $data->{ $key }->{ sum } / $data->{ $key }->{ count } )."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment