Advertisement
cd62131

frequency

Jun 7th, 2018
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.55 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Text::CSV q(csv);
  5. use feature q(say);
  6.  
  7. my $csv = csv(in => \*ARGV, headers => [qw(group name item)]);
  8. my $count = [];
  9. for my $c (@$csv) {
  10.   my $d;
  11.   for (@$count) {
  12.     if ($_->{name} eq $c->{name}) {
  13.       $d = $_;
  14.       last;
  15.     }
  16.   }
  17.   push @$count, ($d = { name => $c->{name} }) unless $d;
  18.   $d->{all}++;
  19.   $d->{hit} = 0 unless $d->{hit};
  20.   $d->{hit}++ if $c->{group} <= 3;
  21. }
  22. $, = ',';
  23. for (sort {$a->{name} cmp $b->{name}} @$count) {
  24.   say $_->{name}, $_->{hit} / $_->{all} * 100;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement