# FILE soccwcomb.pl  working copy  running time  sec

#============= CREATE SCORES PAGE ===================
$scofile='SOCCWsco01.txt'; 
open (SCORES,"<$scofile") || die "Can't open $scorefile $!";
open (SCORESHTML, ">SOCCWscores01.html");
print SCORESHTML "<html><head><title>CIAU football scores 2001</title>
</head>
<body><font size=-1>2001 Womens Soccer Scores</font>
<Font Face=Arial size=-1>\n";

while (<SCORES>) { 
	($date,$Tm1,$Sco1,$Tm2,$Sco2,$GmType,$Notes) = split(':',$_);	

  ### Flag any reversed score, stops program, prints line to warn 
if ($Sco1 < $Sco2) { 
die
print "$date $Tm1 $Sco1 $Tm2 $Sco2 $GmType $Notes";
}
                          # print date if alone on datafile row
if  ($Tm1 le " ") {   
  print SCORESHTML "<br><b>$date</b>\n";
                 }              
                          #print score lines without dates
else {                    
print SCORESHTML "<br>$Tm1 $Sco1 $Tm2 $Sco2 $GmType $Notes\n";
     }
}
print SCORESHTML "</body></html>"; #close HTML file
close SCORESHTML;
close SCORES;

#====================================================
#### TEAM-BY-TEAM SCORES ###
#====================================================

$scofile='SOCCWsco01.txt'; 
open (SCORES,"<$scofile") || die "Can't open $scorefile $!";
open (TEAMDATA, ">soccwteams01.html");
print TEAMDATA "
<HTML><HEAD>

<STYLE>
TD {font: 10pt arial}
</STYLE>
</head>
<BODY bgcolor=white LINK=\"\#0000ff\" VLINK=\"\#0000ff\"> <Font Face=Arial Size=-1>

<TABLE border=0  cellspacing=4 cellpadding=4>
<TR>
<TD  colspan=4 align=center  BGCOLOR=\"\#d2d5e1\">
<B>2001 SOCCW SCORES by Team</B><small>

<TR>
<TD  NOWRAP align=center valign=top BGCOLOR=\"\#d2d5e1\">
<B>Atlantic E</B><Br>
<A HREF=\"\#Acadia\">Acadia</A><Br>
<A HREF=\"\#Dalhousie\">Dalhousie</A><Br>
<A HREF=\"\#Memorial\">Memorial</A><Br>
<A HREF=\"\#Saint Mary's\">Saint Mary's</A><Br>
<A HREF=\"\#StFX\">StFX</A><Br>

<B>Atlantic W</B><Br>
<A HREF=\"\#Moncton\">Moncton</A><Br>
<A HREF=\"\#Mt Allison\">Mt Allison</A><Br>
<A HREF=\"\#UCCB\">UCCB</A><Br>
<A HREF=\"\#UNB\">UNB</A><Br>
<A HREF=\"\#UPEI\">UPEI</A><Br>
<TD  align=center valign=top BGCOLOR=\"\#d2d5e1\">

<B>Quebec</B><Br>
<A HREF=\"\#Bishop's\">Bishop's</A><Br>
<A HREF=\"\#Concordia\">Concordia</A><Br>
<A HREF=\"\#Laval\">Laval</A><Br>
<A HREF=\"\#McGill\">McGill</A><Br>
<A HREF=\"\#Sherbrooke\">Sherbrooke</A><Br>
<A HREF=\"\#UQAM\">UQAM</A><Br>
<A HREF=\"\#UQTR\">UQTR</A><Br>
<Br>
<B>Ontario E</B><Br>
<A HREF=\"\#Carleton\">Carleton</A><Br>
<A HREF=\"\#Ottawa\">Ottawa</A><Br>
<A HREF=\"\#Queen's\">Queen's</A><Br>
<A HREF=\"\#Trent\">Trent</A><Br>
<TD align=center valign=top BGCOLOR=\"\#d2d5e1\">

<B>Ontario NC</B><Br>
<A HREF=\"\#Laurentian\">Laurentian</A><Br>
<A HREF=\"\#Nipissing\">Nipissing</A><Br>
<A HREF=\"\#Toronto\">Toronto</A><Br>
<A HREF=\"\#York\">York</A><Br>

<B>Ontario SC</B><Br>
<A HREF=\"\#Brock\">Brock</A><Br>
<A HREF=\"\#Guelph\">Guelph</A><Br>
<A HREF=\"\#McMaster\">McMaster</A><Br>
<A HREF=\"\#Ryerson\">Ryerson</A><Br>
<TD align=center valign=top BGCOLOR=\"\#d2d5e1\">

<B>Ontario W</B><Br>
<A HREF=\"\#Laurier\">Laurier</A><Br>
<A HREF=\"\#Waterloo\">Waterloo</A><Br>
<A HREF=\"\#Western\">Western</A><Br>
<A HREF=\"\#Windsor\">Windsor</A><Br>
<Br>
<B>CanWest</B><Br>
<A HREF=\"\#Alberta\">Alberta</A><Br>
<A HREF=\"\#Calgary\">Calgary</A><Br>
<A HREF=\"\#Lethbridge\">Lethbridge</A><Br>
<A HREF=\"\#Regina\">Regina</A><Br>
<A HREF=\"\#Saskatchewan\">Saskatchewan</A><Br>
<A HREF=\"\#TWU\">TWU</A><Br>
<A HREF=\"\#Victoria\">Victoria</A><Br>
<A HREF=\"\#UBC\">UBC</A><Br>
</TR></TD></TABLE>
&nbsp;
";

@TeamName = ("Acadia", "Dalhousie", "Memorial", "Saint Mary's", "StFX",
"Moncton", "Mt Allison", "UCCB", "UNB", "UPEI",
"Bishop's", "Concordia", "Laval", "McGill","Sherbrooke", "UQAM", "UQTR", 
"Carleton", "Ottawa", "Queen's", "Trent",
"Brock", "Guelph", "McMaster", "Ryerson", 
"Laurentian", "Nipissing", "Toronto", "York", 
"Laurier", "Waterloo", "Western", "Windsor",   
"Alberta", "Calgary", "Lethbridge", "Regina", "Saskatchewan", "TWU", "Victoria", "UBC");

foreach $team (@TeamName) {
open (TEAMDATA, ">>soccwteams01.html");

print TEAMDATA "<p><dd><big><big><A NAME=\"$team\">$team</A></big></big>\n";

open (SCORES,"<$scofile") || die "Can't open $scorefile $!";
while (<SCORES>) { 
	($Date,$Tm1,$Sco1,$Tm2,$Sco2,$GmType,$Notes) = split(':',$_);	
   
if  ($Tm1 eq $team || $Tm2 eq $team)   {   
  print TEAMDATA "<br>$Date $Tm1 $Sco1 $Tm2 $Sco2 $GmType $Notes\n";
     }
}
}
print TEAMDATA "</body></html>";
close SCORES;

#====================================================
#### CREATING STANDINGS MDA file ###
#====================================================


$scofile='SOCCWsco01.txt'; 
 open (SOCCWMDA, ">soccwstand.txt") || die "Can't open $scorefile $!"; 
print SOCCWMDA "";

@TeamName = ("Acadia", "Dalhousie", "Memorial", "Saint Mary's", "StFX",
"Moncton", "Mt Allison", "UCCB", "UNB", "UPEI",
"Bishop's", "Concordia", "Laval", "McGill","Sherbrooke", "UQAM", "UQTR", 
"Carleton", "Ottawa", "Queen's", "Trent",
"Brock", "Guelph", "McMaster", "Ryerson", 
"Laurentian", "Nipissing", "Toronto", "York", 
"Laurier", "Waterloo", "Western", "Windsor",   
"Alberta", "Calgary", "Lethbridge", "Regina", "Saskatchewan", "TWU", "Victoria", "UBC");


foreach $team (@TeamName) {
  open (SCORES,"<$scofile") || die "Can't open $scorefile $!";
  open (SOCCWMDA, ">>soccwstand.txt") || die "Can't open $scorefile $!"; 

($teamwins, $teamlosses, $pfor, $Against, $WLpct) =0;  # initialize counts
$teamlosses=0; $teamgp=0; $teamties=0; $pfor=0; $Against=0;
$WLpct=0; $Margin=0; $Pts=0; $WLpct=0; $pfpg=0; $papg=0; $mgp=0;  
              # while reading SCORES (SOCCWsco01.txt) line-by-line 
              # parse it at colons : into standings variables  
while (<SCORES>) {    
	($date,$Tm1,$Sco1,$Tm2,$Sco2,$GmType,$Notes) = split(':',$_);	

                   #-------------------------------------------
                   # BEGIN calculation of standings variables.
                   #-------------------------------------------
if ($Tm1 eq $team and $GmType eq "" and $Notes !~ /TIE/ )   { 
                                            # selects Conference only
++$teamgp; ++$teamwins ;                    # counts name in winner column
$pfor = ($pfor + $Sco1);                      # adds winner's score to FOR 
$Against = ($Against + $Sco2);              # adds loser's score to AGAINST
}
elsif ($Tm2 eq $team && $GmType eq "" && $Notes !~ /TIE/ )   {
++$teamgp; ++$teamlosses ;                  # counts name in loser column 
$pfor = ($pfor + $Sco2);                      # adds loser's score to FOR
$Against = ($Against + $Sco1);              # adds winner's score to AGAINST 
}
elsif (($Tm2 eq $team || $Tm1 eq $team) && $GmType eq "" && $Notes =~ "TIE" )   {
++$teamgp; ++$teamties; 
$pfor = ($pfor + $Sco1);                      # adds tie score to FOR
$Against = ($Against + $Sco1);              # adds tie score to AGAINST 
}

$Margin = ($pfor - $Against);                # Calculates +/- diff
$Pts = (3 * $teamwins) + $teamties;

if ($teamgp == 0) {  #NEW
    $WLpct = 1.000 ; #NEW
}                    #NEW
                                     # calc W/L %, elim div by zero 
elsif ($teamlosses == 0 and $teamties == 0 and $teamgp != 0) {  
$WLpct = 1.000;                          #NEW > > > > > > >
}
else {
$WLpct = ( ($teamwins + ($teamties * .5 )) / $teamgp );
}
if ($teamgp != 0) {
$pfpg = ($pfor / $teamgp);
$papg = ($Against / $teamgp);
$mgp = ($Margin / $teamgp);
}

if ($team =~ /Acadia|Dalhousie|Memorial|Saint Mary's|StFX/) {   
   $conf = "aAUSE";
   }
elsif ($team =~ /Moncton|Mt Allison|UCCB|UNB|UPEI/) {   
   $conf = "bAUSW";
   }
elsif ($team =~ /Bishop's|Concordia|Laval|McGill|Sherbrooke|UQAM|UQTR/) {
   $conf = "cQU";
   }
elsif ($team =~ /Carleton|Ottawa|Queen's|Trent/) {
   $conf = "dOUE";
   }
elsif ($team =~ /Laurentian|Nipissing|Toronto|York/) {
   $conf = "eOUNC";
   }
elsif ($team =~ /Brock|Guelph|McMaster|Ryerson/) {
   $conf = "fOUSC";
   }
elsif ($team =~ /Laurier|Waterloo|Western|Windsor/) {
   $conf = "gOUW";
   }
elsif ($team =~ /Alberta|Calgary|Lethbridge|Regina|Saskatchewan|TWU|Victoria|UBC/) {
   $conf = "hCW";
   }
}   
                       # END calculation of standings variables for Team.

print SOCCWMDA "$team:$conf:$teamgp:$teamwins:$teamlosses:$teamties:$pfor:$Against:$Margin:$Pts:$WLpct:$pfpg:$papg:$mgp\n";
}
close SOCCWMDA;

#====================================================
#### SORTING STANDINGS ###
#====================================================

$stanfile='soccwstand.txt'; 
open (SOCCWMDA, "<soccwstand.txt") || die "Can't open $stanfile $!"; 

@mda = <SOCCWMDA>; 
@mdasorted = map { $_->[0] }
 sort {
       $a->[2] cmp $b->[2]
||    $b->[10] <=> $a->[10]
||    $b->[11] <=> $a->[11]
||    $b->[14] <=> $a->[14]
||     $a->[1] cmp $b->[1] 
}
map { [ $_, (split /:/, $_,) ] } 
@mda; 

open (STANHTML, ">soccwstand01.html");
print STANHTM "";
open (STANHTML, ">>soccwstand01.html");

open (STANAUSE, ">soccwstanause.txt");
open (STANAUSW, ">soccwstanausw.txt");
open (STANQUE, ">soccwstanque.txt");
open (STANOUAE, ">soccwstanouae.txt");
open (STANOUANC, ">soccwstanouanc.txt");
open (STANOUASC, ">soccwstanouasc.txt");
open (STANOUAW, ">soccwstanouaw.txt");
open (STANCW, ">soccwstancw.txt");
                         ##CHANGE no's for Men OUAE ++
print STANAUSE @mdasorted[0 .. 4];  ##AUS .. begins zero
print STANAUSW @mdasorted[5 .. 9];  ##AUS .. 
print STANQUE @mdasorted[10 .. 16];  ##Quebec
print STANOUAE @mdasorted[17 .. 20];  ##OUA E
print STANOUANC @mdasorted[21 .. 24];  ##OUA NC   
print STANOUASC @mdasorted[25 .. 28];  ##OUA SC
print STANOUAW @mdasorted[29 .. 32];  ##OUA W
print STANCW @mdasorted[33 .. 40];  ##CanWest

##======================================================
print STANHTML "
<HTML><HEAD><title>SOCCW Standings 2001</title>
<STYLE>
td {font: 10pt arial; text-align:right}
th {font: 10pt arial; font-weight=bold; text-align:right}
</STYLE>
</head>
<BODY bgcolor=white LINK=0000ff VLINK=0000ff> <Font Face=Arial Size=-1>
<TABLE border=0  cellspacing=3 cellpadding=0 bgcolor=white>
<TR>
<TD style=text-align:center colspan=8>
<B>2001 Socc W Standings</B></td></TR>";
##======================================================
##================AUSE=======================
print STANHTML "
<tr><th style=text-align:left> Atlantic E</th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Pct <th></tr>";

open (STANAUSE, "<soccwstanause.txt");

while (<STANAUSE>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$tmpct = sprintf("%.3f", $tmpct);   ## converts to 3 places
$tmpct =~ s/^0/ /g;                 ## replace Leading Zeros

print STANHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $tmpct<td></tr>";
}
##======================================================
##================AUSW=======================
print STANHTML "
<tr><th style=text-align:left> Atlantic W</th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Pct <th></tr>";

open (STANAUSW, "<soccwstanausw.txt");

while (<STANAUSW>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$tmpct = sprintf("%.3f", $tmpct);   ## converts to 3 places
$tmpct =~ s/^0/ /g;                 ## replace Leading Zeros

print STANHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $tmpct<td></tr>";
}
##================QUE=======================

print STANHTML "
<tr><th style=text-align:left> Quebec </th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Pct <th></tr>";

open (STANQUE, "<soccwstanque.txt");

while (<STANQUE>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$tmpct = sprintf("%.3f", $tmpct);   ## converts to 3 places
$tmpct =~ s/^0/ /g;                 ## replace Leading Zeros

print STANHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $tmpct<td></tr>";
}

##================OUAE=======================

print STANHTML "
<tr><th style=text-align:left> Ontario E </th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Pct <th></tr>";

open (STANOUAE, "<soccwstanouae.txt");

while (<STANOUAE>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$tmpct = sprintf("%.3f", $tmpct);   ## converts to 3 places
$tmpct =~ s/^0/ /g;                 ## replace Leading Zeros

print STANHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $tmpct<td></tr>";
}


##================OUANC=======================

print STANHTML "
<tr><th style=text-align:left> Ontario NC</th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Pct <th></tr>";

open (STANOUANC, "<soccwstanouanc.txt");

while (<STANOUANC>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$tmpct = sprintf("%.3f", $tmpct);   ## converts to 3 places
$tmpct =~ s/^0/ /g;                 ## replace Leading Zeros

print STANHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $tmpct<td></tr>";
}


##================OUASC=======================

print STANHTML "
<tr><th style=text-align:left> Ontario SC</th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Pct <th></tr>";

open (STANOUASC, "<soccwstanouasc.txt");

while (<STANOUASC>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$tmpct = sprintf("%.3f", $tmpct);   ## converts to 3 places
$tmpct =~ s/^0/ /g;                 ## replace Leading Zeros

print STANHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $tmpct<td></tr>";
}


##================OUAW=======================

print STANHTML "
<tr><th style=text-align:left> Ontario W</th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Pct <th></tr>";

open (STANOUAW, "<soccwstanouaw.txt");

while (<STANOUAW>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$tmpct = sprintf("%.3f", $tmpct);   ## converts to 3 places
$tmpct =~ s/^0/ /g;                 ## replace Leading Zeros

print STANHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $tmpct<td></tr>";
}

##================CW=======================

print STANHTML "
<tr><th style=text-align:left> CanWest </th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Pct <th></tr>";

open (STANCW, "<soccwstancw.txt");

while (<STANCW>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$tmpct = sprintf("%.3f", $tmpct);   ## converts to 3 places
$tmpct =~ s/^0/ /g;                 ## replace Leading Zeros

print STANHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $tmpct<td></tr>";
}

print STANHTML "</td></tr></table>";
    ### END STANDINGS PAGE ###

##  Tm conf g w l t  f  a    m  p    %    fgp   agp     mgp  
##York:aAUS:8:3:5:0:99:205:-106:6:0.375:12.375:25.625:-13.25
##  1    2  3 4 5 6  7  8    9  10   11    12     13     14

#------------------------------------------------------------------
#------------------------------------------------------------------
    ### PREPARE HIGH SCORING PAGE ###
open (HIGHHTML, ">soccwhigh01.html") || die "Can't open $stanfile $!"; 
print HIGHHTML "";
print HIGHHTML "
<HTML><HEAD><title>SOCCW Highest Scoring 2001</title>
<STYLE>
td {font: 10pt arial; text-align:right}
th {font: 10pt arial; font-weight=bold; text-align:right}
</STYLE>
</head>
<BODY bgcolor=white LINK=0000ff VLINK=0000ff> <Font Face=Arial Size=-1>
<TABLE border=0  cellspacing=3 cellpadding=0 bgcolor=white>
<TR>
<TD align=center colspan=8>
<B>2001 Team Comparisons</B> sorted by:
</td></tr>

<tr><th style=text-align:left>                        High Scoring   </th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Fpg <th></tr>";


open (SOCCWMDA, "<soccwstand.txt") || die "Can't open $stanfile $!";
@mda = <SOCCWMDA>; 
@mdasorted = map { $_->[0] }
 sort {
      $b->[12] <=> $a->[12]   
||    $b->[10] <=> $a->[10]
||    $b->[11] <=> $a->[11]
||    $b->[14] <=> $a->[14]
||     $a->[1] cmp $b->[1] 
}
map { [ $_, (split /:/, $_,) ] } 
@mda; 


open (SOCCWSTANFILE, ">soccwstandtemp.txt") || die "Can't open $stanfile $!";
print SOCCWSTANFILE @mdasorted;
open (SOCCWSTANFILE, "<soccwstandtemp.txt") || die "Can't open $stanfile $!";
while (<SOCCWSTANFILE>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$pfg = sprintf("%.1f", $pfg);    ## converts to 1 place



print HIGHHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $pfg<td></tr>";
}

print HIGHHTML "</td></tr></table>";
    ### END HIGH SCORING PAGE ###
#------------------------------------------------------------------
#------------------------------------------------------------------
    ### PREPARE LEAST SCORED ON PAGE ###
print LEASTHTML "";
open (LEASTHTML, ">soccwleast01.html") || die "Can't open $stanfile $!"; 
print LEASTHTML "";
print LEASTHTML "
<HTML><HEAD><title>SOCCW Least Scored On 2001</title>
<STYLE>
td {font: 10pt arial; text-align:right}
th {font: 10pt arial; font-weight=bold; text-align:right}
</STYLE>
</head>
<BODY bgcolor=white LINK=0000ff VLINK=0000ff> <Font Face=Arial Size=-1>
<TABLE border=0  cellspacing=3 cellpadding=0 bgcolor=white>
<TR>
<TD align=center colspan=8>
<B>2001 Team Comparisons sorted by:</B>
</td></tr>

<tr><th style=text-align:left>                        Least Scored On   </th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Apg <th></tr>";


open (SOCCWMDA, "<soccwstand.txt") || die "Can't open $stanfile $!";
@mda = <SOCCWMDA>; 
@mdasorted = map { $_->[0] }
 sort {
      $a->[13] <=> $b->[13]   
||    $b->[10] <=> $a->[10]
||    $b->[11] <=> $a->[11]
||    $b->[14] <=> $a->[14]
||     $a->[1] cmp $b->[1] 
}
map { [ $_, (split /:/, $_,) ] } 
@mda; 


open (SOCCWSTANFILE, ">soccwstandtemp.txt") || die "Can't open $stanfile $!";
print SOCCWSTANFILE @mdasorted;
open (SOCCWSTANFILE, "<soccwstandtemp.txt") || die "Can't open $stanfile $!";
while (<SOCCWSTANFILE>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$pag = sprintf("%.1f", $pag);    ## converts to 1 place


print LEASTHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $pag<td></tr>";
}

print LEASTHTML "</td></tr></table>";
    ### END LEAST SCORED ON PAGE ###
#------------------------------------------------------------------
#------------------------------------------------------------------
    ### PREPARE MARGIN PAGE ###
print LEASTHTML "";
open (MARGHTML, ">soccwmargin01.html") || die "Can't open $stanfile $!"; 
print MARGHTML "";
print MARGHTML "
<HTML><HEAD><title>SOCCW Least Scored On 2001</title>
<STYLE>
td {font: 10pt arial; text-align:right}
th {font: 10pt arial; font-weight=bold; text-align:right}
</STYLE>
</head>
<BODY bgcolor=white LINK=0000ff VLINK=0000ff> <Font Face=Arial Size=-1>
<TABLE border=0  cellspacing=3 cellpadding=0 bgcolor=white>
<TR>
<TD align=center colspan=8>
<B>2001 Team Comparisons sorted by:</B>
</td></tr>

<tr><th style=text-align:left>   WL Margin   </th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Mpg <th></tr>";


open (SOCCWMDA, "<soccwstand.txt") || die "Can't open $stanfile $!";
@mda = <SOCCWMDA>; 
@mdasorted = map { $_->[0] }
 sort {
      $b->[14] <=> $a->[14]   
||    $b->[10] <=> $a->[10]
||    $b->[11] <=> $a->[11]
||     $a->[1] cmp $b->[1] 
}
map { [ $_, (split /:/, $_,) ] } 
@mda; 


open (SOCCWSTANFILE, ">soccwstandtemp.txt") || die "Can't open $stanfile $!";
print SOCCWSTANFILE @mdasorted;
open (SOCCWSTANFILE, "<soccwstandtemp.txt") || die "Can't open $stanfile $!";
while (<SOCCWSTANFILE>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$pmg = sprintf("%.1f", $pmg);    ## converts to 1 place


print MARGHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $pmg<td></tr>";
}

print MARGHTML "</td></tr></table>";
    ### END MARGIN PAGE ###

#------------------------------------------------------------------
#------------------------------------------------------------------
    ### PREPARE WL PERCENT PAGE ###
open (PCTHTML, ">soccwpercent01.html") || die "Can't open $stanfile $!"; 
print PCTHTML "";
print PCTHTML "
<HTML><HEAD><title>SOCCW Least Scored On 2001</title>
<STYLE>
td {font: 10pt arial; text-align:right}
th {font: 10pt arial; font-weight=bold; text-align:right}
</STYLE>
</head>
<BODY bgcolor=white LINK=0000ff VLINK=0000ff> <Font Face=Arial Size=-1>
<TABLE border=0  cellspacing=3 cellpadding=0 bgcolor=white>
<TR>
<TD align=center colspan=8>
<B>2001 Team Comparisons sorted by:</B>
</td></tr>

<tr><th style=text-align:left>                        WL Percent   </th><th>W </th><th>L </th><th>T </th><th>  F  </th><th>   A </th><th>  P </th><th>Pct <th></tr>";


open (SOCCWMDA, "<soccwstand.txt") || die "Can't open $stanfile $!";
@mda = <SOCCWMDA>; 
@mdasorted = map { $_->[0] }
 sort {
      $b->[11] <=> $a->[11]   
||    $b->[10] <=> $a->[10]
||    $b->[14] <=> $a->[14]
||     $a->[1] cmp $b->[1] 
}
map { [ $_, (split /:/, $_,) ] } 
@mda; 


open (SOCCWSTANFILE, ">soccwstandtemp.txt") || die "Can't open $stanfile $!";
print SOCCWSTANFILE @mdasorted;
open (SOCCWSTANFILE, "<soccwstandtemp.txt") || die "Can't open $stanfile $!";
while (<SOCCWSTANFILE>) { 
	($tm,$tmconf,$tmgp,$tmw,$tml,$tmt,$tmf,$tma,$tmm,$tmpts,$tmpct,$pfg,$pag,$pmg) = split(':',$_);	

$tmpct = sprintf("%.3f", $tmpct);   ## converts to 3 places
$tmpct =~ s/^0/ /g;                 ## replace Leading Zeros

print PCTHTML "
<tr><td style=text-align:left>$tm     </td><td>$tmw</td><td>$tml</td><td>$tmt</td><td>$tmf</td><td>$tma</td><td> $tmpts</td><td> $tmpct<td></tr>";
}

print PCTHTML "</td></tr></table>";

    ### END WL PERCENT PAGE ###
#------------------------------------------------------------------
#------------------------------------------------------------------



