perl version of histogram prog
authorAndrew Tridgell <tridge@samba.org>
Fri, 12 Feb 2010 00:16:14 +0000 (11:16 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 12 Feb 2010 00:16:14 +0000 (11:16 +1100)
histogram.pl [new file with mode: 0755]

diff --git a/histogram.pl b/histogram.pl
new file mode 100755 (executable)
index 0000000..9a85b62
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/perl -w
+
+my %data;
+my $total = 0;
+
+while (<>) {
+       my $v = $_;
+       chomp($v);
+       $data{$v}++;
+       $total++;
+}
+
+my $accum = 0;
+my $line = 0;
+
+foreach my $v (sort { $data{$a} <=> $data{$b} } keys %data) {
+    $accum += $data{$v};
+    printf "%d (%.0f%% / %.0f%%) %s  (%u)\n", 
+    $data{$v}, 
+    (100*$data{$v})/$total, 
+    (100*$accum)/$total, 
+    $v,
+    $line;
+    $line++;
+}