Part 1

#!/usr/bin/perl

while(<>)
{
        split;
        next unless ($_[0] > 0 and $_[0] < 31);
        $day = $_[0];
        $spread = $_[1] - $_[2];
        unless (defined $min_spread)
        {
                $spread_day = $day;
                $min_spread = $spread;
        }
        if ($spread <= $min_spread)
        {
                $spread_day = $day;
                $min_spread = $spread;
        }
}
print $spread_day, "\n";

Part 2

#!/usr/bin/perl

while(<>)
{
        split;
        next unless ($_[0] > 0 and $_[0] < 21);
        $team = $_[1];
        $spread = abs($_[6] - $_[8]);
        unless (defined $min_spread)
        {
                $spread_team = $team;
                $min_spread = $spread;
        }
        if ($spread <= $min_spread)
        {
                $spread_team = $team;
                $min_spread = $spread;
        }
}
print $spread_team, "\n";

Part 3

#!/usr/bin/perl

sub dm($$$$)
{
        my $file = shift;
        my $label_col = shift;
        my $alpha_col = shift;
        my $beta_col = shift;

        my ($spread_label, $min_spread) = ("", 100000);

        open (IN, "<$file");
        while(<IN>)
        {
                split;
                next unless ($_[$alpha_col] =~ /^[0-9]+/);
                next unless ($_[$beta_col] =~ /^[0-9]+/);
                my $label = $_[$label_col];
                my $spread = abs($_[$alpha_col] - $_[$beta_col]);
                unless (defined $min_spread)
                {
                        print ".";
                        $spread_label = $label;
                        $min_spread = $spread;
                }
                if ($spread <= $min_spread)
                {
                        $spread_label = $label;
                        $min_spread = $spread;
                }
        }
        close (IN);
        $spread_label;
}

print "part1: ", dm("../K4Weather.txt", 0, 1, 2), "\n";
print "part2: ", dm("../K4Soccer.txt", 1, 6, 8), "\n";