Skip to content

Instantly share code, notes, and snippets.

@jwodder
Created June 26, 2014 23:20
Show Gist options
  • Save jwodder/10acad4754f292723cd7 to your computer and use it in GitHub Desktop.
Save jwodder/10acad4754f292723cd7 to your computer and use it in GitHub Desktop.
Unique NetHack deaths
#!/usr/bin/perl -wnl
# A Perl script for printing all unique NetHack deaths incurred and their
# frequencies, based on a shell script posted to RGRN by "Faux_Pseudo"
# Written 12 Nov 2008 by John T. Wodder II
# Last edited 14 Nov 2008 by John Wodder
# Usage: deaths.pl [-sw] [logfile ...]
# Options:
# -s - If no logfiles are given on the command line, read from stdin instead
# of /usr/games/lib/nethackdir/logfile
# -w - Strip off any "while helpless" messages & similar stuff that comes
# after a comma in the cause of death
use strict;
use Getopt::Std;
our(%deaths, %opts);
BEGIN {
getopts('sw', \%opts);
@ARGV or $opts{s} or @ARGV = ('/usr/games/lib/nethackdir/logfile');
}
s/^[^,]*,//;
$opts{w} && s/,.*$//;
$deaths{$_}++;
END {
printf "%8d %s\n", $deaths{$_}, $_
for sort { $deaths{$b} <=> $deaths{$a} || $a cmp $b } keys %deaths
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment