Skip to content

Instantly share code, notes, and snippets.

@supki
Created June 26, 2012 20:26
Show Gist options
  • Save supki/2998703 to your computer and use it in GitHub Desktop.
Save supki/2998703 to your computer and use it in GitHub Desktop.
Silly stuff to get hackage authors sorted by productivity.
#!/usr/bin/env perl
# This crappy perl script parses .cabal files for `authors' field and extracts authors names. Then it collects them in one enormous hash associating total number of findings. Then it "pretty"-prints hash from most productive authors to least productive.
use v5.14;
use warnings FATAL => qw(void);
# Skip all lines before /^author:/i one, then return it.
sub lex ($) {
my $h = $_[0];
while (<$h>) { if (/^author:/i) { return $_ } }
}
# Remove occasional stuff-stuff, <stuff> or (stuff) and also preceding and trailing spaces.
sub parse ($) {
map { s/\<.*?\>//g # remove all <stuff>
; s/\(.*?\)//g # remove all (stuff)
; s/^\s+// # remove preceding spaces
; s/\s+$//r # remove trailing spaces
} split ",|&| and ", $_[0] =~ s/^author://ri;
}
# Construct authors hash
my %authors;
while (<>) {
chomp $_;
open(my $h, "<:utf8", $_) or die "Can't open $_: $!\n";
map { $authors{ $_ }++ } parse lex $h
}
# Prettyprint it!
for my $key (sort { $authors{$b} <=> $authors{$a} } keys %authors) { say "$key - $authors{$key}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment