Skip to content

Instantly share code, notes, and snippets.

@dedeibel
Forked from jkramer/chart.pl
Created October 27, 2009 13:31
Show Gist options
  • Save dedeibel/219557 to your computer and use it in GitHub Desktop.
Save dedeibel/219557 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use Chart::Pie;
use IO::File;
my $pie = Chart::Pie->new(640, 480);
my $score;
# My script shell isn't zsh so HISTFILE was not set,
# let it be specified
my $histfile_arg = $ARGV[0];
my $histfile = $ENV{HISTFILE} || $histfile_arg;
my $io = new IO::File($histfile);
for($io->getlines) {
# It seems like I have a different history file format, make the
# prefix optional
/^(?:\s*\d*:\d*;)?(\w+)/ or next;
++$score->{$1};
}
my $top = {
map { $_ => $score->{$_} }
(sort { $score->{$b} <=> $score->{$a} } keys %$score)[0 .. 9]
};
$pie->add_dataset(keys %$top);
$pie->add_dataset(values %$top);
$pie->png("history.png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment