#!/usr/bin/perl -w
use Tk;
sub parsepage {
my $index;
my $start;
my $string = '';
for ($index = 0; $index <= $#_; $index++) {
$start = $index;
$index++ while $index < $#_ and $_[$index] + 1 == $_[$index + 1];
if ($index - $start > 1) {
$string .= ", $_[$start]-$_[$index]";
}
elsif ($index - $start == 1) {
$string .= ", $_[$start], $_[$index]";
}
else {
$string .= ", $_[$index]";
}
}
$string =~ s/^, //;
$string;
}
sub incrpage {
$page++;
$pageinc->configure(-text => $page);
}
sub endprog {
for $this (keys %maps) {
my $pages = parsepage @{$this};
print "
$maps{$this}$pages\n"
}
exit;
}
$main = MainWindow->new();
$page = 1;
$pageinc = $main->Button(-text => $page, -command => \&incrpage)->pack;
$main->Button(-text => 'End', -command => \&endprog)->pack;
while () {
chomp;
if ($. % 4 == 1) {
$frame = $main->Frame();
$frame->pack(-side => 'top');
}
($translated = $_) =~ y/A-Za-z0-9/_/c;
$maps{$translated} = $_;
$frame->Button(-command => eval "sub {push \@$translated, \$page}",
-text => $_)->pack(-side => 'left');
}
MainLoop;
__END__
Hobbes
Mom
Dad
Suzie Derkins
Mrs. Wormwood
Rosalyn
Moe
The Principal
Wagon Rides
School
Chocolate Frosted Sugar Bombs
Bathtime
Pouncing
Baseball
Bedtime
Snowballs
"Dad Polls"
Spaceman Spiff
Tracer Bullet
Snowmen
Monsters under the Bed
Camping
Stupendous Man
Football
Christmas
Hamster Huey and the Gooey Kablooie
Homework
Transmogrifier
Waiting for the bus
Dinner table
Water balloons
Water fights
Saturday Morning Cartoons
Photographs
Dinosaurs
Toboggan Rides
Hobbes in the laundry
Aliens
Snow fort
Cafeteria
Philosophical Discussions
Valentine's Day
G.R.O.S.S.