#!/usr/bin/perl
use warnings;
use strict;

use DBI;
use Config::Simple;

my $year = shift || 2007;
my $config_file = shift || 'nfl.config';
my %db_hash;
Config::Simple->import_from( $config_file, \%db_hash );

my $db   = "nfl_$year";
my $user = $db_hash{"${db}.user"} || "default_user";
my $pass = $db_hash{"${db}.pass"} || "default_password";

my $dbh = DBI->connect( "DBI:mysql:$db", "$user", "$pass" )
  or die("Cannot connect to the database");
my $sql = "drop table if exists games";
my $sth = $dbh->prepare($sql);
$sth->execute;
$sql = "create table games (
    id INT NOT NULL AUTO_INCREMENT, 
    week INT NOT NULL,
    visitor VARCHAR(80), 
    visit_score INT NOT NULL, 
    home VARCHAR(80), 
    home_score INT NOT NULL,
    PRIMARY KEY (id))
    ENGINE=MyISAM";

$sth = $dbh->prepare($sql);
$sth->execute;
$dbh->disconnect;