This is a handy little command-line perl script that allows a comparison of a user against a professional player in the database.

#!/usr/bin/perl
$home=$ENV{"HOME"};

$hole = "Hole 1 2 3 4 5 6 7 8 9 Out 10 11 12 13 14 15 16 17 18 In Total";
foreach $arg (@ARGV)
{
$db = "tourdb.txt";
open (DB,$db);
@db=<DB>;
close (DB);
$szdb="" . @db;
$title = $arg . " Comparison";@final = ();push(@final, $title);
$dbcount = $found = $start = $end = 0;
while($dbcount < $szdb)
{
# Look for the player in $arg, If found, mark the beginning, look
# for the end and mark it, if found, step out of the loop
if($db[$dbcount] =~ /$arg/)
{$found = 1;$start = $dbcount;}
if(($found == 1) && ($db[$dbcount] =~ /STOP/))
{$end = $dbcount; last;}
$dbcount++;
}
if($found) # If found, Parse the data.
{&findPLAYERS();}
else
{print STDOUT "$arg couldn't be found in $db.";} # Otherwise, generate an error.
}

sub findPLAYERS
{
$dbcount = $start;
while($dbcount < $szdb)
{
# Step through array from 'start', making sure not to go past the end
if($db[$dbcount] =~ /\bpar\b|\bPar\b|\bPAR\b/)
{ # Look for header data
if($db[$dbcount + 1] =~ /^\W/)
{$par = $db[$dbcount] . $db[$dbcount + 1];}
else{$par = $db[$dbcount];}
(@par) = split(/\s+/, $par);
if($par[10] < 6)
{@par = &addOUTin(@par)}
$szpar = "" . @par;
$count = 0;
while($count < $szpar)
{
if($par[$count] =~ /\w+/)
{
$pushpar .= $par[$count] . " ";
}
$count++;
}
push(@final, $hole, $pushpar);
}
elsif(($db[$dbcount] !~ /^\W/) && ($db[$dbcount] !~ /STOP/))
{# Look for player data
if($db[$dbcount + 1] =~ /^\W/)
{$player = $db[$dbcount] . $db[$dbcount + 1];}
else{$player = $db[$dbcount];}
(@player) = split(/\s+/, $player);
if($player[10] < 6){@player = &addOUTin(@player);}
$pcount = $dbcount + 2;
while($pcount < $szdb)
{
if($db[$pcount] =~ /$arg/)
{$tripped = 1;}
if(($tripped) && ($db[$pcount] =~ /STOP/))
{$tripped = 0;}
if(($db[$pcount] =~ /^$player[0]/) && ($tripped == 1))
{
if($db[$pcount + 1] =~ /^\W/)
{$newplayer = $db[$pcount] . $db[$pcount + 1];}
else{$newplayer = $db[$pcount];}
(@newplayer) = split(/\s+/, $newplayer);
if($newplayer[10] < 6){@newplayer = &addOUTin(@newplayer);}
$sznew = "" . @newplayer;
$compcount = 1;
while($compcount < $sznew)
{
$player[$compcount] = ($player[$compcount] + $newplayer[$compcount])/2;
$compcount++;
}
$tripped = 0;
}
$pcount++;
}
$szplay = "" . @player;
if($szplay > 10)
{
$count = 0;
$pushplayer = "";
while($count < $szplay)
{
if($player[$count] =~ /\w+/)
{
$pushplayer .= $player[$count] . " ";
}
$count++
}
push(@final, $pushplayer);
}
}
# Look for the end of the data
else{if($db[$dbcount] =~ /STOP/){last;}}
$dbcount++
}
&tallyFILE();
&printTOfile();
}

sub addOUTin
{
# Organize Back and Front 9
local(@outin);
@new = ();
$szoutin = "". @outin;
if($szoutin > 10)
{
print STDOUT "I'm in addOUTin, the value at position 10 was $outin[10] for $outin[0].\n";
$count = 1;$out = $in = $total = 0;
$szarray = "" . @outin;
while($count < $szarray)
{
if($count <= 9){$out += $outin[$count];}
elsif(($count > 9) && ($count <= 18)){$in += $outin[$count];}
else{}
$count++;
}
push(@new, $outin[1..9], $out, $outin[10..18], $in, $total);
@new;
}
}

sub printTOfile
{
# Generate HTML file with tableized data
$count = 0;
$szfinal = "" . @final;
$title = $final[0];
$title =~ s/\W//g;
$title = $title . ".html";
open(FILE, ">" . $title);
while($count <= $szfinal)
{
if($count == 0)
{
print FILE "<html><head><title>$final[$count]</title></head>\n";
print FILE "<body bgcolor= #FFFFFF>\n<!--#exec cmd=\"/navad\"-->\n<h1><center>$final[$count]</center></h1>\n";
print FILE "<center><table cellpadding= 2 cellspacing= 1 border= 1 width= 70% align= \"CENTER\">";
}
else
{
$final[$count] =~ s/\s+/<\/TD><td>/g;
$final[$count] = "<tr align= center><td>" . $final[$count] . "</td></tr>\n";
print FILE $final[$count];
}
$count++;
}
print FILE "</table></p></center><!--#exec cmd=\"/address\"--></body></html>\n";
close(FILE);
}

sub tallyFILE
{
# Do the math, generate averages/totals
$count = 1;
$incount = 0;
$szfinal = "" . @final;
@done = ();
while($count <= $szfinal)
{
if($final[$count] =~ /^\bpar\b|^\bPar\b|^\bPAR\b|^\bhole\b|^\bHole\b|^\bHOLE\b|^\W/){}
else
{
(@line) = split(/\s/, $final[$count]);
$szline = "" . @line;
$compcount = 0;
while($compcount < $szline)
{
$done[$compcount] = $done[$compcount] + $line[$compcount];
$compcount++;
}
if(($line[5] =~ /\d+/) && ($line[0] !~ /^\bpar\b|^\bPar\b|^\bPAR\b|^\bhole\b|^\bHole\b|^\bHOLE\b|^\W/))
{$incount++;}
}
$count++;
}
$done[0] = "Average";
$count = 0;
while($count < $szplay)
{
if($done[$count] =~ /\w+/)
{
if($count == 0)
{$totalstring .= $done[$count] . " ";}
else
{
$done[$count] = int(($done[$count]/$incount) +.5);
$totalstring .= $done[$count] . " ";
}
}
$count++
}
push(@final, $totalstring);
}


Back    Home