summaryrefslogtreecommitdiff
path: root/tools/percentile.pl
blob: 37e60688a93bfac6d13bcd99b6e12d432f469334 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#! /usr/bin/perl -w

use strict;
use Symbol;

main: {
  my @buf = ();
  my $running = 0;
  my $file = $ARGV[0]
    || die "usage: $0 filename\n";
  my $inch = Symbol::gensym;
  open($inch, '<', $file)
    || die "Could not open input file '$file'\n";
  while (my $line = <$inch>) {
    chomp $line;
    push @buf, $line;
    my @stuff = split(' ', $line);
    $running += $stuff[0];
  }
  close $inch;
  my $total = $running;
  $running = 0;
  open($inch, '<', $file)
    || die "Could not reopen input file '$file'\n";
  while (my $line = <$inch>) {
    chomp $line;
    push @buf, $line;
    my @stuff = split(' ', $line);
    $running += $stuff[0];
    my $frac = 100 * $running / $total;
    if (0) {
      printf("%5d %5d %5.1f %s\n",
        $stuff[0], $running, $frac, $stuff[1]);
    } else {
      print 'blacklist_from *@', $stuff[1], "\n";
    }
  }

}