Script only displaying last entries made

Thread Solved

Join Date: Sep 2005
Posts: 175
Reputation: kahaj is an unknown quantity at this point 
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Script only displaying last entries made

 
0
  #1
Dec 5th, 2007
I thought this script was working. I absolutely cannot get IIS to fully and completely work on my home comp. After making a special trip to school to test this thing out, it ends up that it's only displaying the last data entered instead of the averages, totals, etc. This thing is due for class tomorrow. I've changed around a few things here & there and it's still working no better (no worse either, far as that goes). Anyone have a clue what I need to do? In case it's needed, I'll post both the .html & the .cgi.

  1. #!C:/Perl/bin/perl.exe
  2. #Football Stats
  3. print "Content-type: text/html\n\n";
  4. use CGI qw(:standard);
  5. use strict;
  6. use SDBM_File;
  7. use Fcntl;
  8.  
  9. ##########variable declarations and input assignments#############################
  10. my ($yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $homeCount, $awayCount, $turnovAllowedPGame, $tds, $tdsAllowed, $sacksTotal, $sacksPerGameAvg, $sacksAllowedTotal, $sacksAllowedAvg, $turnovForcedTotal, $turnovForcedAvg, $turnovAllowedTotal, $turnovAllowedAvg, $wins, $losses, $winPercent, $winPercentHome, $winPercentAway, $winLose, $tieGames, $tdsAllowedTotal,
  11. $rushYrdTotal, $passYrdTotal, $tdsTotal, $tdsAvg, $tdsAllowedAvg, $tdsAvg, $rushYrdAvg, $yourTmScoreTotal, $otherTmScoreTotal,
  12. $otherTmScoreAvg, $yourTmScoreAvg, $passYrdAvg);
  13. my $weekNum = param('weekNum');
  14. my $whereAt = param('gamePlayed');
  15. my $homeCounter = 0;
  16. my $awayCounter = 0;
  17. my $yourTmScore = param('yourTmScore');
  18. my $otherTmScore = param('otherTmScore');
  19. my $passYrdPGame = param('passYrdPGame');
  20. my $rushYrdPGame = param('rushYrdPGame');
  21. my $sacks = param('sacks');
  22. my $sacksAllowed = param('sacksAllowed');
  23. my $turnovForcedPerGame = param('turnovForcedPerGame');
  24. my $turnovAllowedPGame = param('turnovAllowedPGame');
  25. my $tds = param('tds');
  26. my $tdsTotal = $tds + $tdsTotal;
  27. my $tdsAllowed = param('tdsAllowed');
  28. $tdsAllowedTotal = $tdsAllowed + $tdsAllowedTotal;
  29. $rushYrdTotal = $rushYrdPGame + $rushYrdTotal;
  30. $passYrdTotal = $passYrdPGame + $passYrdTotal;
  31. $yourTmScoreTotal = $yourTmScore + $yourTmScoreTotal;
  32. $otherTmScoreTotal = $otherTmScore + $otherTmScoreTotal;
  33. $sacksTotal = $sacks + $sacksTotal;
  34. $sacksAllowedTotal = $sacksAllowed + $sacksAllowedTotal;
  35. $turnovForcedTotal = $turnovForcedTotal + $turnovForcedPerGame;
  36. $turnovAllowedTotal = $turnovAllowedTotal + $turnovAllowedPGame;
  37.  
  38.  
  39.  
  40. ########save to file#######################################
  41. open(OUTFILE, ">>","nflStats.txt")
  42. or die "Error opening nflStats.txt $!, stopped";
  43. print OUTFILE join(':::',
  44. $weekNum, $whereAt, $yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $sacks, $sacksAllowed, $turnovForcedPerGame,
  45. $turnovAllowedPGame, $tds, $tdsAllowed), "\n";
  46. close(OUTFILE);
  47.  
  48.  
  49.  
  50. ####################### do calculations (in while loop) ##################
  51. open(INFILE, "<", "nflStats.txt");
  52.  
  53. my $ctr = 0;
  54.  
  55. while(<INFILE>) {
  56. $ctr = $ctr + 1;
  57. my ($weekNum, $whereAt, $yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $sacks, $sacksAllowed, $turnovForcedPerGame,
  58. $turnovAllowedPGame, $tds, $tdsAllowed) = split(':::');
  59.  
  60.  
  61. my $tdsAvg = $tdsAvg/$ctr;
  62. my $tdsAllowedAvg = $tdsAllowedAvg/$ctr;
  63. my $rushYrdAvg = $rushYrdTotal/$ctr;
  64. my $passYrdAvg = $passYrdTotal/$ctr;
  65. my $yourTmScoreAvg = $yourTmScoreTotal/$ctr;
  66. my $otherTmScoreAvg = $otherTmScoreTotal/$ctr;
  67. my $sacksPerGameAvg = $sacksTotal/$ctr;
  68. my $sacksAllowedAvg = $sacksAllowedTotal/$ctr;
  69. my $turnovForcedAvg = $turnovForcedTotal/$ctr;
  70. my $turnovAllowedAvg = $turnovAllowedTotal/$ctr;
  71.  
  72. if ($whereAt eq 'Home')
  73. {
  74. $homeCounter = $homeCounter + 1;
  75. }
  76. elsif ($whereAt eq 'Away')
  77. {
  78. $awayCounter = $awayCounter + 1;
  79. }
  80.  
  81. if ($yourTmScore > $otherTmScore)
  82. {
  83. $wins = $wins + 1;
  84. }
  85. else
  86. {
  87. $losses = $losses + 1;
  88. }
  89. if ($yourTmScore == $otherTmScore)
  90. {
  91. $tieGames = $tieGames + 1;
  92. }
  93. }
  94. close INFILE;
  95. ######################### end while loop #########################
  96.  
  97.  
  98.  
  99. ################ generate page #########################
  100. print <<endHtml;
  101. <html>
  102. <head><title>Current Cowboys Statistics</title>
  103. <script type="text/javascript">
  104. window.defaultStatus = "Results so far...";
  105. </script></head>
  106. <body link="navy" vlink="navy" alink="navy">
  107. <font size="3">
  108.  
  109. <font size="6"><div align="center">Weeks played: $weekNum</div></font><br /><br />
  110.  
  111. <hr width="90%" color="#CCCCCC" size="4"><br /><br />
  112.  
  113. <p>
  114. <table width="750" border="1" bgcolor="navy" align="center">
  115. <tr>
  116. <td colspan="4" bgcolor="white"><font size="4" color="navy"><div align="center"><b>SCORING</b></div></font></td>
  117. </tr>
  118. <tr><td colspan="2"><font size="3" color="white"><div align="center"><b>OWN</b></div></font></td><td colspan="2"><font size="3" color="white"><div align="center"><b>OPPONENT</b></div></font></td>
  119. </tr>
  120. <tr>
  121. <td width="25%"><font size="3" color="white"><div align="center">Points Scored Total</div></font></td>
  122. <td width="25%"><font size="3" color="white"><div align="center">Points Averaged per Game</div></font></td>
  123. <td width="25%"><font size="3" color="white"><div align="center">Points Allowed Total</div></font></td>
  124. <td width="25%"><font size="3" color="white"><div align="center">Points Allowed Avg. per Game</div></font></td>
  125. </tr>
  126. <tr>
  127. <td width="25%"><font size="3" color="white"><div align="center">$yourTmScoreTotal</div></font></td>
  128. <td width="25%"><font size="3" color="white"><div align="center">$yourTmScoreAvg</div></font></td>
  129. <td width="25%"><font size="3" color="white"><div align="center">$otherTmScoreTotal</div></font></td>
  130. <td width="25%"><font size="3" color="white"><div align="center">$otherTmScoreAvg</div></font></td>
  131. </tr>
  132. </table>
  133. </p><br />
  134.  
  135. <table width="85%" border="0" align="center">
  136. <tr>
  137. <td width="50%" align="center">
  138.  
  139. <p>
  140. <table width="300" border="1" bgcolor="navy">
  141. <tr>
  142. <td colspan="2" bgcolor="white"><b><font size="4" color="navy"><div align="center">GAME LOCATIONS</div></font></b></td>
  143. </tr>
  144. <tr>
  145. <td width="50%"><div align="center"><font size="3" color="white">Home:</font></div></td>
  146. <td width="50%"><div align="center"><font size="3" color="white">Away:</font></div></td>
  147. </tr>
  148. <tr>
  149. <td width="50%"><div align="center"><font size="3" color="white">$homeCounter</font></div></td>
  150. <td width="50%"><div align="center"><font size="3" color="white">$awayCounter</font></div></td>
  151. </tr>
  152. </table>
  153. </p>
  154. </td>
  155. <td width="50%" align="center">
  156. <p>
  157. <table width="300" border="1" bgcolor="navy">
  158. <tr>
  159. <td colspan="3" bgcolor="white"><font size="4" color="navy"><div align="center"><b>WINS & LOSSES</b></div></font></td>
  160. </tr>
  161. <tr>
  162. <td width="33%"><div align="center"><font size="3" color="white">Wins</font></td>
  163. <td width="33%"><div align="center"><font size="3" color="white">Losses</font></td>
  164. <td width="33%"><div align="center"><font size="3" color="white">Ties</font></td>
  165. </tr>
  166. <tr>
  167. <td width="33%"><div align="center"><font size="3" color="white">$wins</font></td>
  168. <td width="33%"><div align="center"><font size="3" color="white">$losses</font></td>
  169. <td width="33%"><div align="center"><font size="3" color="white">$tieGames</font></td>
  170. </tr>
  171. </table>
  172. </p>
  173. </td>
  174. </tr>
  175. </table><br />
  176.  
  177. <p>
  178. <table width="750" border="1" bgcolor="navy" align="center">
  179. <tr>
  180. <td colspan="4"bgcolor="white"><font size="4" color="navy"><div align="center"><b>TOUCHDOWNS</b></div></font></td>
  181. </tr>
  182. <tr><td colspan="2"><font size="3" color="white"><div align="center"><b>TD's MADE</b></div></font></td><td colspan="2"><font size="3" color="white"><div align="center"><b>TD's ALLOWED</b></div></font></td>
  183. </tr>
  184. <tr>
  185. <td width="25%"><font size="3" color="white"><div align="center">Total Touchdowns</div></font></td>
  186. <td width="25%"><font size="3" color="white"><div align="center">TD's Avg. per Game</div></font></td>
  187. <td width="25%"><font size="3" color="white"><div align="center">Total Touchdowns Allowed</div></font></td>
  188. <td width="25%"><font size="3" color="white"><div align="center">TD's Allowed Avg. per Game</div></font></td>
  189. </tr>
  190. <tr>
  191. <td width="25%"><font size="3" color="white"><div align="center">$tdsTotal</div></font></td>
  192. <td width="25%"><font size="3" color="white"><div align="center">$tdsAvg</div></font></td>
  193. <td width="25%"><font size="3" color="white"><div align="center">$tdsAllowedTotal</div></font></td>
  194. <td width="25%"><font size="3" color="white"><div align="center">$tdsAllowedAvg</div></font></td>
  195. </tr>
  196. </table>
  197. </p><br />
  198.  
  199.  
  200. <p>
  201. <table width="750" border="1" bgcolor="navy" align="center">
  202. <tr>
  203. <td colspan="4" bgcolor="white"><font size="4" color="navy"><div align="center"><b>OFFENSIVE PERFORMANCE</b></div></font></td>
  204. </tr>
  205. <tr><td colspan="2"><font size="3" color="white"><div align="center"><b>RUSHING YARDS</b></div></font></td><td colspan="2"><font size="3" color="white"><div align="center"><b>PASSING YARDS</b></div></font></td>
  206. </tr>
  207. <tr>
  208. <td width="25%"><font size="3" color="white"><div align="center">Total Rushing Yards</div></font></td>
  209. <td width="25%"><font size="3" color="white"><div align="center">Rushing Yards Avg. per Game</div></font></td>
  210. <td width="25%"><font size="3" color="white"><div align="center">Total Passing Yards</div></font></td>
  211. <td width="25%"><font size="3" color="white"><div align="center">Passing Yards Avg. per Game</div></font></td>
  212. </tr>
  213. <tr>
  214. <td width="25%"><font size="3" color="white"><div align="center">$rushYrdTotal</div></font></td>
  215. <td width="25%"><font size="3" color="white"><div align="center">$rushYrdAvg</div></font></td>
  216. <td width="25%"><font size="3" color="white"><div align="center">$passYrdTotal</div></font></td>
  217. <td width="25%"><font size="3" color="white"><div align="center">$passYrdAvg</div></font></td>
  218. </tr>
  219. </table>
  220. </p><br />
  221.  
  222. <p>
  223. <table width="750" border="1" bgcolor="navy" align="center">
  224. <tr>
  225. <td colspan="4" bgcolor="white"><font size="4" color="navy"><div align="center"><b>SACKS</b></div></font></td>
  226. </tr>
  227. <tr>
  228. <td width="25%"><font size="3" color="white"><div align="center">Total Sacks Made</div></font></td>
  229. <td width="25%"><font size="3" color="white"><div align="center">Sacks Made Avg. per Game</div></font></td>
  230. <td width="25%"><font size="3" color="white"><div align="center">Total Sacks Allowed</div></font></td>
  231. <td width="25%"><font size="3" color="white"><div align="center">Sacks Allowed Avg. per Game</div></font></td>
  232. </tr>
  233. <tr>
  234. <td width="25%"><font size="3" color="white"><div align="center">$sacksTotal</div></font></td>
  235. <td width="25%"><font size="3" color="white"><div align="center">$sacksPerGameAvg</div></font></td>
  236. <td width="25%"><font size="3" color="white"><div align="center">$sacksAllowedTotal</div></font></td>
  237. <td width="25%"><font size="3" color="white"><div align="center">$sacksAllowedAvg</div></font></td>
  238. </tr>
  239. </table>
  240. </p><br />
  241.  
  242. <p>
  243. <table width="750" border="1" bgcolor="navy" align="center">
  244. <tr>
  245. <td colspan="4" bgcolor="white"><font size="4" color="navy"><div align="center"><b>TURNOVERS</b></div></font></td>
  246. </tr>
  247. <tr>
  248. <td width="25%"><font size="3" color="white"><div align="center">Total Turnovers Made</div></font></td>
  249. <td width="25%"><font size="3" color="white"><div align="center">Turnovers Avg. per Game</div></font></td>
  250. <td width="25%"><font size="3" color="white"><div align="center">Total Turnovers Allowed</div></font></td>
  251. <td width="25%"><font size="3" color="white"><div align="center">Turnovers Allowed Avg. per Game</div></font></td>
  252. </tr>
  253. <tr>
  254. <td width="25%"><font size="3" color="white"><div align="center">$turnovForcedTotal</div></font></td>
  255. <td width="25%"><font size="3" color="white"><div align="center">$turnovForcedAvg</div></font></td>
  256. <td width="25%"><font size="3" color="white"><div align="center">$turnovAllowedTotal</div></font></td>
  257. <td width="25%"><font size="3" color="white"><div align="center">$turnovAllowedAvg</div></font></td>
  258. </tr>
  259. </table>
  260. </p><br />
  261.  
  262. <p><font size="5" face="Arial Black"><a href="" onclick="self.close();">Close Window</a><br /><br />
  263. <a href="C:\Inetpub\wwwroot\public_html\Perl Semester Project\nflStats.html">Enter more stats</a></font></p>
  264.  
  265.  
  266. </font>
  267. </body></html>
  268. endHtml


  1. <!nflStats.html>
  2. <html>
  3. <head><title>Stats For the Dallas Cowboys</title>
  4. <script type="text/javascript">
  5. window.defaultStatus = "Keep up with the Cowboys this year!";
  6.  
  7.  
  8. function confirmSubmit() {
  9. var submitForm = window.confirm("Make sure that all of the fields have been filled in completely.");
  10. if (submitForm == true)
  11. return true;
  12. return false;
  13. }
  14.  
  15. function confirmReset() {
  16. var resetForm = window.confirm("Are you sure you want to clear all of the above contents?");
  17. if (resetForm == true)
  18. return true;
  19. return false;
  20. }
  21.  
  22. function showPics(linkTarget) {
  23. picWindow = window.open(linkTarget, "showPics", "toolbar=no,menubar=no,location=no,scrollbars=no,resiable=no,width=550,height=570");
  24. }
  25.  
  26. </script></head>
  27. <body background="nflShield.bmp">
  28.  
  29. <table width="55%" border="0" align="center" cellpadding="5">
  30. <tr>
  31. <td bgcolor="#000066"><div align="center"><font size="5" color="#FFFFFF">Use the fields below to enter weekly stats<br />for the Dallas Cowboys.</font></div></td>
  32. </tr>
  33. </table>
  34.  
  35. <form action="http://localhost/cgi-bin/nflStats.cgi" method="post" onsubmit="return confirmSubmit();" onreset="return confirmReset();">
  36. <font size="4" face="Arial">
  37.  
  38. <table width="97%" border="0" align="center">
  39. <tr><td colspan="4"><hr color="#CCCCCC" /></td></tr>
  40.  
  41. <tr>
  42. <td width="25%" valign="top" align="left">
  43. <p>Week of the game:
  44. <select name="weekNum">
  45. <option></option>
  46. <option>1</option>
  47. <option>2</option>
  48. <option>3</option>
  49. <option>4</option>
  50. <option>5</option>
  51. <option>6</option>
  52. <option>7</option>
  53. <option>8</option>
  54. <option>9</option>
  55. <option>10</option>
  56. <option>11</option>
  57. <option>12</option>
  58. <option>13</option>
  59. <option>14</option>
  60. <option>15</option>
  61. <option>16</option>
  62. <option>17</option>
  63. </select></p>
  64. </td>
  65. <td width="25%" align="right" valign="top">
  66. <p>Played at:<br />
  67. Home<input type="radio" name="gamePlayed" value="Home"> Away<input type="radio" name="gamePlayed" value="Away"></p>
  68. </td>
  69. <td width="25%" align="right" valign="top">
  70. <p>Touchdowns: <input type="text" name="tds" size="3" maxlength="2"></p>
  71. </td>
  72. <td width="25%" align="right" valign="top">
  73. <p>Touchdowns Allowed <input type="text" name="tdsAllowed" size="3" maxlength="2"></p>
  74. </td>
  75. </tr>
  76.  
  77. <tr><td colspan="4"><hr color="#CCCCCC" /></td></tr>
  78. <tr>
  79. <td width="25%" valign="top" align="left">
  80. <p>Cowboys' Score: <input type="text" name="yourTmScore" size="3" maxlength="3"></p>
  81. </td>
  82. <td width="25%" align="right">
  83. <p>Opponent's Score: <input type="text" name="otherTmScore" size="3" maxleghth="3"></p>
  84. </td>
  85. <td width="25%" align="right" valign="top">
  86. <p>Passing Yards: <input type="text" name="passYrdPGame" size="4" maxlength="3"></p>
  87. </td>
  88. <td width="25%" valign="top" align="right">
  89. <p>Rushing Yards: <input type="text" name="rushYrdPGame" size="4" maxlength="3"></p>
  90. </td>
  91. </tr>
  92.  
  93. <tr><td colspan="4"><hr color="#CCCCCC" /></td></tr>
  94.  
  95. <tr>
  96. <td width="25%" align="left" valign="top">
  97. Sacks Made: <input type="text" name="sacks" size="3" maxlength="2">
  98. </td>
  99. <td width="25%" align="right" valign="top">
  100. Sacks Allowed: <input type="text" name="sacksAllowed" size="3" maxlength="2">
  101. </td>
  102. <td width="25%" valign="top" align="right">
  103. Turn Overs Forced: <input type="text" name="turnovForcedPerGame" size="3" maxlength="2">
  104. </td>
  105. <td width="25%" align="right" valign="top">
  106. Turn Overs Allowed: <input type="text" name="turnovAllowedPGame" size="3" maxlength="2">
  107. </td>
  108. </tr>
  109. </table>
  110.  
  111.  
  112. </font>
  113. <div align="right"><input type="submit" value="Submit Stats">
  114. <input type="reset" value="Reset Stats"></div>
  115. </form><br />
  116.  
  117. <table width="85%" align="center" border="0">
  118. <tr>
  119. <td width="50% align="left" valign="top">
  120. <script type="text/javascript">
  121.  
  122. // Create arrays to contain all the values
  123. // for links and image locations
  124. var link = new Array;
  125. var image = new Array;
  126.  
  127. link[1] = 'http://www.dallascowboys.com';
  128. link[2] = "http://www.nfl.com";
  129. link[3] = "http://www.nflplayers.com";
  130. link[4] = "http://www.nfl.com/probowl";
  131. link[5] = "http://www.superbowl.com";
  132.  
  133. image[1] = "bannerCowboysDotCom.jpg";
  134. image[2] = "bannerNFLDotCom.jpg";
  135. image[3] = "bannerNFLPlayers.jpg";
  136. image[4] = "bannerProBowl.jpg";
  137. image[5] = "bannerSuperBowl.jpg";
  138.  
  139. // Create a random number between 1 and last number
  140. random_num = (Math.round((Math.random()*4)+1));
  141.  
  142.  
  143. // Write a link and images with random array
  144. document.write('<a href="' + link[random_num] + '" target="_blank">');
  145. document.write('<img src="' + image[random_num] + '" border="0"></a>');
  146.  
  147. </script>
  148. </td>
  149. <td width="50%" align="right" valign="top">
  150. <a href="cpic1.html" onmouseover="self.status='View Cowboys pictures here';return true" onclick="showPics('cpic1.html');return false"><img src="cowboyPics.jpg" border="0"></a>
  151. </td>
  152. </tr>
  153. </table>
  154.  
  155. </body>
  156. </html>
  157.  
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Script only displaying last entries made

 
0
  #2
Dec 6th, 2007
You have to generate your output while the file is opened and you are processing the data line by line. You generate the output after the file is closed, so naturally you will only ever get the last line of the file. A generic example of one way to do it:

  1. print "<table>";
  2. while (<INPUT_FROM_FILE>) {
  3. # do some stuff here with your data like split() and calculating averages, etc.
  4. print "<tr><td>$yourdata</td></tr>\n";
  5. }
  6. print "</table>";
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 175
Reputation: kahaj is an unknown quantity at this point 
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Re: Script only displaying last entries made

 
0
  #3
Dec 6th, 2007
So do I need to put a while loop in for each single cell, or can I do it like this:

  1. #!C:/Perl/bin/perl.exe
  2. #Football Stats
  3. print "Content-type: text/html\n\n";
  4. use CGI qw(:standard);
  5. use strict;
  6. use SDBM_File;
  7. use Fcntl;
  8.  
  9. ##########variable declarations and input assignments#############################
  10. my ($yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $homeCount, $awayCount, $turnovAllowedPGame, $tds, $tdsAllowed, $sacksTotal, $sacksPerGameAvg, $sacksAllowedTotal, $sacksAllowedAvg, $turnovForcedTotal, $turnovForcedAvg, $turnovAllowedTotal, $turnovAllowedAvg, $wins, $losses, $winPercent, $winPercentHome, $winPercentAway, $winLose, $tieGames, $tdsAllowedTotal,
  11. $rushYrdTotal, $passYrdTotal, $tdsTotal, $tdsAvg, $tdsAllowedAvg, $tdsAvg, $rushYrdAvg, $yourTmScoreTotal, $otherTmScoreTotal,
  12. $otherTmScoreAvg, $yourTmScoreAvg, $passYrdAvg);
  13. my $weekNum = param('weekNum');
  14. my $whereAt = param('gamePlayed');
  15. my $homeCounter = 0;
  16. my $awayCounter = 0;
  17. my $yourTmScore = param('yourTmScore');
  18. my $otherTmScore = param('otherTmScore');
  19. my $passYrdPGame = param('passYrdPGame');
  20. my $rushYrdPGame = param('rushYrdPGame');
  21. my $sacks = param('sacks');
  22. my $sacksAllowed = param('sacksAllowed');
  23. my $turnovForcedPerGame = param('turnovForcedPerGame');
  24. my $turnovAllowedPGame = param('turnovAllowedPGame');
  25. my $tds = param('tds');
  26. my $tdsTotal = $tds + $tdsTotal;
  27. my $tdsAllowed = param('tdsAllowed');
  28. $tdsAllowedTotal = $tdsAllowed + $tdsAllowedTotal;
  29. $rushYrdTotal = $rushYrdPGame + $rushYrdTotal;
  30. $passYrdTotal = $passYrdPGame + $passYrdTotal;
  31. $yourTmScoreTotal = $yourTmScore + $yourTmScoreTotal;
  32. $otherTmScoreTotal = $otherTmScore + $otherTmScoreTotal;
  33. $sacksTotal = $sacks + $sacksTotal;
  34. $sacksAllowedTotal = $sacksAllowed + $sacksAllowedTotal;
  35. $turnovForcedTotal = $turnovForcedTotal + $turnovForcedPerGame;
  36. $turnovAllowedTotal = $turnovAllowedTotal + $turnovAllowedPGame;
  37.  
  38.  
  39.  
  40. ########save to file#######################################
  41. open(OUTFILE, ">>","nflStats.txt")
  42. or die "Error opening nflStats.txt $!, stopped";
  43. print OUTFILE join(':::',
  44. $weekNum, $whereAt, $yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $sacks, $sacksAllowed, $turnovForcedPerGame,
  45. $turnovAllowedPGame, $tds, $tdsAllowed), "\n";
  46. close(OUTFILE);
  47.  
  48.  
  49.  
  50. ####################### do calculations (in while loop) ##################
  51. open(INFILE, "<", "nflStats.txt");
  52.  
  53. my $ctr = 0;
  54.  
  55. while(<INFILE>) {
  56. $ctr = $ctr + 1;
  57. my ($weekNum, $whereAt, $yourTmScore, $otherTmScore, $passYrdPGame, $rushYrdPGame, $sacks, $sacksAllowed, $turnovForcedPerGame,
  58. $turnovAllowedPGame, $tds, $tdsAllowed) = split(':::');
  59.  
  60.  
  61. my $tdsAvg = $tdsAvg/$ctr;
  62. my $tdsAllowedAvg = $tdsAllowedAvg/$ctr;
  63. my $rushYrdAvg = $rushYrdTotal/$ctr;
  64. my $passYrdAvg = $passYrdTotal/$ctr;
  65. my $yourTmScoreAvg = $yourTmScoreTotal/$ctr;
  66. my $otherTmScoreAvg = $otherTmScoreTotal/$ctr;
  67. my $sacksPerGameAvg = $sacksTotal/$ctr;
  68. my $sacksAllowedAvg = $sacksAllowedTotal/$ctr;
  69. my $turnovForcedAvg = $turnovForcedTotal/$ctr;
  70. my $turnovAllowedAvg = $turnovAllowedTotal/$ctr;
  71.  
  72. if ($whereAt eq 'Home')
  73. {
  74. $homeCounter = $homeCounter + 1;
  75. }
  76. elsif ($whereAt eq 'Away')
  77. {
  78. $awayCounter = $awayCounter + 1;
  79. }
  80.  
  81. if ($yourTmScore > $otherTmScore)
  82. {
  83. $wins = $wins + 1;
  84. }
  85. else
  86. {
  87. $losses = $losses + 1;
  88. }
  89. if ($yourTmScore == $otherTmScore)
  90. {
  91. $tieGames = $tieGames + 1;
  92. }
  93.  
  94.  
  95.  
  96. ################ generate page #########################
  97. print <<endHtml;
  98. <html>
  99. <head><title>Current Cowboys Statistics</title>
  100. <script type="text/javascript">
  101. window.defaultStatus = "Results so far...";
  102. </script></head>
  103. <body link="navy" vlink="navy" alink="navy">
  104. <font size="3">
  105.  
  106. <font size="6"><div align="center">Weeks played: $weekNum</div></font><br /><br />
  107.  
  108. <hr width="90%" color="#CCCCCC" size="4"><br /><br />
  109.  
  110. <p>
  111. <table width="750" border="1" bgcolor="navy" align="center">
  112. <tr>
  113. <td colspan="4" bgcolor="white"><font size="4" color="navy"><div align="center"><b>SCORING</b></div></font></td>
  114. </tr>
  115. <tr><td colspan="2"><font size="3" color="white"><div align="center"><b>OWN</b></div></font></td><td colspan="2"><font size="3" color="white"><div align="center"><b>OPPONENT</b></div></font></td>
  116. </tr>
  117. <tr>
  118. <td width="25%"><font size="3" color="white"><div align="center">Points Scored Total</div></font></td>
  119. <td width="25%"><font size="3" color="white"><div align="center">Points Averaged per Game</div></font></td>
  120. <td width="25%"><font size="3" color="white"><div align="center">Points Allowed Total</div></font></td>
  121. <td width="25%"><font size="3" color="white"><div align="center">Points Allowed Avg. per Game</div></font></td>
  122. </tr>
  123. <tr>
  124. <td width="25%"><font size="3" color="white"><div align="center">$yourTmScoreTotal</div></font></td>
  125. <td width="25%"><font size="3" color="white"><div align="center">$yourTmScoreAvg</div></font></td>
  126. <td width="25%"><font size="3" color="white"><div align="center">$otherTmScoreTotal</div></font></td>
  127. <td width="25%"><font size="3" color="white"><div align="center">$otherTmScoreAvg</div></font></td>
  128. </tr>
  129. </table>
  130. </p><br />
  131.  
  132. <table width="85%" border="0" align="center">
  133. <tr>
  134. <td width="50%" align="center">
  135.  
  136. <p>
  137. <table width="300" border="1" bgcolor="navy">
  138. <tr>
  139. <td colspan="2" bgcolor="white"><b><font size="4" color="navy"><div align="center">GAME LOCATIONS</div></font></b></td>
  140. </tr>
  141. <tr>
  142. <td width="50%"><div align="center"><font size="3" color="white">Home:</font></div></td>
  143. <td width="50%"><div align="center"><font size="3" color="white">Away:</font></div></td>
  144. </tr>
  145. <tr>
  146. <td width="50%"><div align="center"><font size="3" color="white">$homeCounter</font></div></td>
  147. <td width="50%"><div align="center"><font size="3" color="white">$awayCounter</font></div></td>
  148. </tr>
  149. </table>
  150. </p>
  151. </td>
  152. <td width="50%" align="center">
  153. <p>
  154. <table width="300" border="1" bgcolor="navy">
  155. <tr>
  156. <td colspan="3" bgcolor="white"><font size="4" color="navy"><div align="center"><b>WINS & LOSSES</b></div></font></td>
  157. </tr>
  158. <tr>
  159. <td width="33%"><div align="center"><font size="3" color="white">Wins</font></td>
  160. <td width="33%"><div align="center"><font size="3" color="white">Losses</font></td>
  161. <td width="33%"><div align="center"><font size="3" color="white">Ties</font></td>
  162. </tr>
  163. <tr>
  164. <td width="33%"><div align="center"><font size="3" color="white">$wins</font></td>
  165. <td width="33%"><div align="center"><font size="3" color="white">$losses</font></td>
  166. <td width="33%"><div align="center"><font size="3" color="white">$tieGames</font></td>
  167. </tr>
  168. </table>
  169. </p>
  170. </td>
  171. </tr>
  172. </table><br />
  173.  
  174. <p>
  175. <table width="750" border="1" bgcolor="navy" align="center">
  176. <tr>
  177. <td colspan="4"bgcolor="white"><font size="4" color="navy"><div align="center"><b>TOUCHDOWNS</b></div></font></td>
  178. </tr>
  179. <tr><td colspan="2"><font size="3" color="white"><div align="center"><b>TD's MADE</b></div></font></td><td colspan="2"><font size="3" color="white"><div align="center"><b>TD's ALLOWED</b></div></font></td>
  180. </tr>
  181. <tr>
  182. <td width="25%"><font size="3" color="white"><div align="center">Total Touchdowns</div></font></td>
  183. <td width="25%"><font size="3" color="white"><div align="center">TD's Avg. per Game</div></font></td>
  184. <td width="25%"><font size="3" color="white"><div align="center">Total Touchdowns Allowed</div></font></td>
  185. <td width="25%"><font size="3" color="white"><div align="center">TD's Allowed Avg. per Game</div></font></td>
  186. </tr>
  187. <tr>
  188. <td width="25%"><font size="3" color="white"><div align="center">$tdsTotal</div></font></td>
  189. <td width="25%"><font size="3" color="white"><div align="center">$tdsAvg</div></font></td>
  190. <td width="25%"><font size="3" color="white"><div align="center">$tdsAllowedTotal</div></font></td>
  191. <td width="25%"><font size="3" color="white"><div align="center">$tdsAllowedAvg</div></font></td>
  192. </tr>
  193. </table>
  194. </p><br />
  195.  
  196.  
  197. <p>
  198. <table width="750" border="1" bgcolor="navy" align="center">
  199. <tr>
  200. <td colspan="4" bgcolor="white"><font size="4" color="navy"><div align="center"><b>OFFENSIVE PERFORMANCE</b></div></font></td>
  201. </tr>
  202. <tr><td colspan="2"><font size="3" color="white"><div align="center"><b>RUSHING YARDS</b></div></font></td><td colspan="2"><font size="3" color="white"><div align="center"><b>PASSING YARDS</b></div></font></td>
  203. </tr>
  204. <tr>
  205. <td width="25%"><font size="3" color="white"><div align="center">Total Rushing Yards</div></font></td>
  206. <td width="25%"><font size="3" color="white"><div align="center">Rushing Yards Avg. per Game</div></font></td>
  207. <td width="25%"><font size="3" color="white"><div align="center">Total Passing Yards</div></font></td>
  208. <td width="25%"><font size="3" color="white"><div align="center">Passing Yards Avg. per Game</div></font></td>
  209. </tr>
  210. <tr>
  211. <td width="25%"><font size="3" color="white"><div align="center">$rushYrdTotal</div></font></td>
  212. <td width="25%"><font size="3" color="white"><div align="center">$rushYrdAvg</div></font></td>
  213. <td width="25%"><font size="3" color="white"><div align="center">$passYrdTotal</div></font></td>
  214. <td width="25%"><font size="3" color="white"><div align="center">$passYrdAvg</div></font></td>
  215. </tr>
  216. </table>
  217. </p><br />
  218.  
  219. <p>
  220. <table width="750" border="1" bgcolor="navy" align="center">
  221. <tr>
  222. <td colspan="4" bgcolor="white"><font size="4" color="navy"><div align="center"><b>SACKS</b></div></font></td>
  223. </tr>
  224. <tr>
  225. <td width="25%"><font size="3" color="white"><div align="center">Total Sacks Made</div></font></td>
  226. <td width="25%"><font size="3" color="white"><div align="center">Sacks Made Avg. per Game</div></font></td>
  227. <td width="25%"><font size="3" color="white"><div align="center">Total Sacks Allowed</div></font></td>
  228. <td width="25%"><font size="3" color="white"><div align="center">Sacks Allowed Avg. per Game</div></font></td>
  229. </tr>
  230. <tr>
  231. <td width="25%"><font size="3" color="white"><div align="center">$sacksTotal</div></font></td>
  232. <td width="25%"><font size="3" color="white"><div align="center">$sacksPerGameAvg</div></font></td>
  233. <td width="25%"><font size="3" color="white"><div align="center">$sacksAllowedTotal</div></font></td>
  234. <td width="25%"><font size="3" color="white"><div align="center">$sacksAllowedAvg</div></font></td>
  235. </tr>
  236. </table>
  237. </p><br />
  238.  
  239. <p>
  240. <table width="750" border="1" bgcolor="navy" align="center">
  241. <tr>
  242. <td colspan="4" bgcolor="white"><font size="4" color="navy"><div align="center"><b>TURNOVERS</b></div></font></td>
  243. </tr>
  244. <tr>
  245. <td width="25%"><font size="3" color="white"><div align="center">Total Turnovers Made</div></font></td>
  246. <td width="25%"><font size="3" color="white"><div align="center">Turnovers Avg. per Game</div></font></td>
  247. <td width="25%"><font size="3" color="white"><div align="center">Total Turnovers Allowed</div></font></td>
  248. <td width="25%"><font size="3" color="white"><div align="center">Turnovers Allowed Avg. per Game</div></font></td>
  249. </tr>
  250. <tr>
  251. <td width="25%"><font size="3" color="white"><div align="center">$turnovForcedTotal</div></font></td>
  252. <td width="25%"><font size="3" color="white"><div align="center">$turnovForcedAvg</div></font></td>
  253. <td width="25%"><font size="3" color="white"><div align="center">$turnovAllowedTotal</div></font></td>
  254. <td width="25%"><font size="3" color="white"><div align="center">$turnovAllowedAvg</div></font></td>
  255. </tr>
  256. </table>
  257. </p><br />
  258.  
  259. <p><font size="5" face="Arial Black"><a href="" onclick="self.close();">Close Window</a><br /><br />
  260. <a href="C:\Inetpub\wwwroot\public_html\Perl Semester Project\nflStats.html">Enter more stats</a></font></p>
  261.  
  262.  
  263. </font>
  264. </body></html>
  265. endHtml
  266.  
  267. }
  268. close INFILE;
  269. ######################### end while loop #########################


-I can't truly run it at home to know for sure.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: Script only displaying last entries made

 
0
  #4
Dec 6th, 2007
Not exactly like that but that is the general idea.

Pseudo code:

here print all html haedrs and any stuff that gets printed before opening the file.

open file

while (<>){
here print only the stuff that gets generated from reading the file
}

close file

print the ending html stuff here
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: Script only displaying last entries made

 
0
  #5
Dec 6th, 2007
  1. #!C:/Perl/bin/perl.exe
  2. #Football Stats
  3. print "Content-type: text/html\n\n";
  4. use CGI qw(:standard);
  5. use strict;
  6. use SDBM_File;
  7. use Fcntl;

8X---------snip
tons of code deleted
8X---------snip

First thing I would suggest you do is start using 'warnings'. That may point out a lot of syntax errors for you.

use warnings;

-I can't truly run it at home to know for sure.
Then why not install Apache?
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 175
Reputation: kahaj is an unknown quantity at this point 
Solved Threads: 0
kahaj kahaj is offline Offline
Junior Poster

Re: Script only displaying last entries made

 
0
  #6
Dec 6th, 2007
I have all of figured out, working 100% correctly now. Thanks for your help on this one.

For another week, until classes are done, I haven't the time to mess with Apache.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC