#! /usr/local/bin/perl # $Id: hdhd.pl,v 1.1 2004/03/25 20:03:55 jzap Exp $ $| = 1; print < EOF @query = split( /&/, $ENV{ 'QUERY_STRING'}); for $query( @query) { ($name, $value) = split( /=/, $query); $value =~ tr/A-Z/a-z/; push @team, $value if $name eq 'team'; } # print "@query \n"; # print "@team \n"; $nteam = @team; if( $nteam != 2) { print "Head-to-Head Results: Error\n"; print "\n"; print "Sorry, you selected $nteam teams.
\n"; print "Please select two and only two teams, and try again.
\n"; print "\n"; exit; } &init_team; $team0 = $team_abbr{ $team[ 0]}; $team1 = $team_abbr{ $team[ 1]}; push @ng, $team[ 0] if ! $team0; push @ng, $team[ 1] if ! $team1; # print "t0=$team0 t1=$team1 \n"; if( @ng > 0) { print "Head-to-Head Results: Error\n"; print "\n"; print "Sorry, you selected an unknown team: @ng
\n"; print "Please try again.
\n"; print "\n"; exit; } open IDX, '/web/nhl/lib/Year/game-index'; while( ) { tr/A-Z/a-z/; ($date, $gnum, $ateam, $at, $hteam) = split; next unless $ateam eq $team0 && $hteam eq $team1 || $ateam eq $team1 && $hteam eq $team0 ; $idx{ $date} = $_; $num_home_games{ $hteam} += 1; } close IDX; $home_game_adv{ $team0} = $num_home_games{ $team0} - $num_home_games{ $team1}; $home_game_adv{ $team1} = $num_home_games{ $team1} - $num_home_games{ $team0}; open RES, '/web/nhl/lib/Year/game-res'; while( ) { # 20001004 0001 col 2 dal 2 f/ot # 20001005 0005 det 4 cgy 3 final tr/A-Z/a-z/; ($date, $gnum, $ateam, $agoal, $hteam, $hgoal, $fstat) = split; next unless $ateam eq $team0 && $hteam eq $team1 || $ateam eq $team1 && $hteam eq $team0 ; $res{ $date} = $_; } close RES; print < Head-to-Head Results: $team0 vs $team1
    head-to-head tiebreaker results: $team0 vs $team1
EOF

print " " x 48, "$team0  $team1\n";
for $date( sort keys %idx)
{
    $_ = $res{ $date};
    if( defined $_)
    {   ($date, $gnum, $ateam, $agoal, $hteam, $hgoal, $fstat) = split;
	($t0goal = $agoal, $t1goal = $hgoal) if $team0 eq $ateam;
	($t0goal = $hgoal, $t1goal = $agoal) if $team0 eq $hteam;
	$t0pts = $t0goal > $t1goal ? 2 : $fstat eq "f/ot" ? 1 : 0;
	$t1pts = $t1goal > $t0goal ? 2 : $fstat eq "f/ot" ? 1 : 0;

    }
    else
    {   $_ = $idx{ $date};
	($date, $gnum, $ateam, $at, $hteam) = split;
	$agoal = $hgoal = '-';
	$t0pts = $t1pts = '-';
	$fstat = 'sched';
    }

    printf( "    %8d  %04d  %3s %2s  @  %3s %2s  %-7s",
	$date, $gnum, $ateam, $agoal, $hteam, $hgoal, $fstat);
    if( $home_game_adv{ $hteam}-- > 0)
    {   print "    x    x  home-game adv\n";
	next;
    }

    printf( "   %2s   %2s\n", $t0pts, $t1pts);
    $t0tot += $t0pts;
    $t1tot += $t1pts;
}
print "\n", " " x 27;
printf( "head-to-head points:  %2d   %2d\n\n", $t0tot, $t1tot);
print "";
print "    show tiebreaker data for other teams\n";
print "    visit the nhl.jzap.com home page\n";
print "";
print "
\n"; sub init_team { %team_abbr = ( 'ana' => 'ana', 'mighty.ducks' => 'ana', 'atl' => 'atl', 'thrashers' => 'atl', 'bos' => 'bos', 'bruins' => 'bos', 'buf' => 'buf', 'sabres' => 'buf', 'car' => 'car', 'hurricanes' => 'car', 'cbj' => 'cbj', 'clb' => 'cbj', 'clm' => 'cbj', 'cls' => 'cbj', 'cob' => 'cbj', 'blue.jackets' => 'cbj', 'cal' => 'cgy', 'cgy' => 'cgy', 'flames' => 'cgy', 'blackhawks' => 'chi', 'chi' => 'chi', 'col' => 'col', 'avalanche' => 'col', 'dal' => 'dal', 'stars' => 'dal', 'det' => 'det', 'red.wings' => 'det', 'edm' => 'edm', 'oilers' => 'edm', 'fla' => 'fla', 'flo' => 'fla', 'panthers' => 'fla', 'la' => 'los', 'lak' => 'los', 'los' => 'los', 'kings' => 'los', 'min' => 'min', 'wild' => 'min', 'mon' => 'mon', 'mtl' => 'mon', 'canadiens' => 'mon', 'nas' => 'nas', 'nsh' => 'nas', 'predators' => 'nas', 'nj' => 'njd', 'njd' => 'njd', 'devils' => 'njd', 'nyi' => 'nyi', 'islanders' => 'nyi', 'nyr' => 'nyr', 'rangers' => 'nyr', 'ott' => 'ott', 'senators' => 'ott', 'phi' => 'phi', 'flyers' => 'phi', 'pho' => 'pho', 'phx' => 'pho', 'coyotes' => 'pho', 'pit' => 'pit', 'pgh' => 'pit', 'penguins' => 'pit', 'san' => 'san', 'sj' => 'san', 'sjs' => 'san', 'sharks' => 'san', 'stl' => 'stl', 'blues' => 'stl', 'tam' => 'tam', 'tb' => 'tam', 'tbl' => 'tam', 'lightning' => 'tam', 'tor' => 'tor', 'maple.leafs' => 'tor', 'van' => 'van', 'canucks' => 'van', 'was' => 'was', 'wsh' => 'was', 'capitals' => 'was', ); }