#!/usr/bin/perl use strict; my $SCORES = 'scores.txt'; # Format of scores file is: # visitors score hometeam score # one score per line # for games not yet played, scores are 0 # Like: Patriots 20 Rams 17 my $OFF = 42; # Default offense rating my $DEF = 21; # Default defense rating my $HOME = 3; # Home field advantage my $ADJUST = 7; # Adjustment factor my (%nfl, $wins, $loss, $length); if (!open (IN, $SCORES)) { printf STDERR "\nError opening file: $SCORES\n$!\n\n"; exit; } while (chomp (my $line = )) { if ($line =~ m{__END__}) { last; } if ($line =~ m{^\s*$}) { next; } if ($line =~ m{^\s*#}) { print "$line\n"; next; } if ($line =~ m{(\S.*\S)\s+(\d+)\s+(\S.*\S)\s+(\d+)}) { my ($away, $anum, $home, $hnum) = ($1, $2, $3, $4); if (!defined($nfl{$away})) { $nfl{$away} = { off => $OFF, def => $DEF}; if (length($away) > $length) { $length = length($away); } } if (!defined($nfl{$home})) { $nfl{$home} = { off => $OFF, def => $DEF}; if (length($home) > $length) { $length = length($home); } } my $atry = int($nfl{$away}->{off} - $nfl{$home}->{def}); my $htry = int($nfl{$home}->{off} - $nfl{$away}->{def} + $HOME); if ($atry == $htry) { $htry++; } my ($actual, $guess, $result); if ($anum != 0 || $hnum != 0) { $actual = $hnum - $anum; $guess = $htry - $atry; if ($actual * $guess > 0) { $wins++; $result = '++'; } else { $loss++; $result = ' '; } adjust($nfl{$away}, $nfl{$home}, $anum, $atry); adjust($nfl{$home}, $nfl{$away}, $hnum, $htry); } printf (STDOUT "%-*.*s %2.2d (%2.2d) \n", $length, $length, $away, $anum, $atry); printf (STDOUT "%-*.*s %2.2d (%2.2d) ", $length, $length, $home, $hnum, $htry); printf (STDOUT "%+2.2d (%+2.2d) %s\n\n", $actual, $guess, $result); } else { print STDERR "Unknown format:$line\n"; } } for my $team (sort { $b->[0] <=> $a->[0] } map { [ $nfl{$_}->{off} + $nfl{$_}->{def}, $_]; } keys(%nfl)) { $team = $team->[1]; printf(STDOUT "%-*.*s %4.1f %4.1f %4.1f\n", $length, $length, $team, $nfl{$team}->{off} + $nfl{$team}->{def}, $nfl{$team}->{off}, $nfl{$team}->{def}) } printf (STDOUT "\nW:$wins L:$loss %5.2f%\n", ($wins / ($wins + $loss)) * 100); #----------------------------------------------------------- sub adjust { my ($team, $oppo, $score, $guess) = @_; my $adjust = ($score - $guess) / $ADJUST; $team->{off} += $adjust; $oppo->{def} -= $adjust; }