#!/usr/bin/perl use strict; #my $start = (times)[0]; my $game = ""; my $num = ""; $game = $ARGV[0] or die "Usage: %lb [#scores]\n"; if ($ARGV[1] =~ /\d+/) { if ($ARGV[1] > 0) { $num = int($ARGV[1]); } else { $num = 3; } } else { $num = 3; } use LWP::Simple; my $URL = "http://marp.retrogames.com/index.cgi?mode=fe_scores&short=" . $game; my $i = 0; my $output = "Fetching the top $num scores for $game...please wait\n"; for (split(/\n/, get($URL))) { # Strips the () and the

from the whole line if ($_ =~ /^\((.*)\)

/) { my @line = split(/,/, $1); # Skip the header line if ($line[0] eq "recording_score") { next; } else { # Strip the '' from each field my $game_position = ($line[9] =~ /'(.*)'/)[0]; #$game_position =~ s/L$//; # temp fix my $game_score = ($line[0] =~ /'(.*)'/)[0]; #$game_score =~ s/L$//; # temp fix my $game_date = ($line[4] =~ /'(.*)'/)[0]; my $game_player = ($line[7] =~ /'(.*)'/)[0]; my $game_desc = ($line[11] =~ /'(.*)'/)[0]; if ($game_desc) { $game_desc =~ s/<.+?>//g; $game_desc =~ s/\r/ /g; $game_desc = " : " . $game_desc; if (length($game_desc) > 200) { $game_desc = substr($game_desc, 0, 200) . " [...]"; } } my (undef,undef,undef,$mday,$mon,$year,undef,undef,undef) = gmtime($game_date); $mon = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[$mon]; $year += 1900; $output .= "$game_position: $game_score ($mon $mday $year) $game_player $game_desc\n"; $i++; } } if ($i == $num) { last; } } if ($i == 0) { $output = "Sorry, no scores found for $game."; } #my $end = (times)[0]; #my $time = $end - $start; #print $output . "(that took $time CPU seconds)\n"; print $output; exit 0;