Skip to content

Instantly share code, notes, and snippets.

@sharifulin
Last active December 20, 2015 04:09
Show Gist options
  • Save sharifulin/6069214 to your computer and use it in GitHub Desktop.
Save sharifulin/6069214 to your computer and use it in GitHub Desktop.
use v5.12;
use List::Util 'sum';
my $data = [
map {
chomp;
my $res; @$res{qw(impr clicks ctr cost)} = grep { s/\s+//sg; s/,/./sg; s/%//sg; 1 } split /\t/; $res;
}
<DATA>
];
for my $key (qw(impr clicks cost)) {
say join ' : ', ucfirst $key, sum map $_->{$key}, @$data;
}
say 'CTR : ' . (sprintf "%.2f%", sum(map $_->{ctr}, @$data) / scalar @$data);
__END__
72 416 204 0,28% 236,80 0,00
145 0 0% 0,00 0,00
26 123 145 0,56% 435,00 0,00
3 179 19 0,60% 22,80 0,00
33 374 66 0,20% 79,20 0,00
992 963 1 136 0,11% 3 408,00 0,00
333 954 457 0,14% 548,40 0,00
69 397 372 0,54% 446,40 0,00
1 481 006 8 429 0,57% 25 287,00 0,00
794 145 4 175 0,53% 5 010,00 0,00
2 595 603 3 980 0,15% 7 308,00 0,00
745 375 1 958 0,26% 2 274,00 0,00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment