Ok. Time to ask for help. Remember me? The guy who wanted to write a program to update goalie stats?
Well, I wrote a script that runs and essentially does what I want it to do, but has a couple problems. For now, Im settling for a simple program where I input the stats by hand and the program updates the stats and prints the HTML for me to cut and paste to the site. This will make it much easier for me than updating the HTML by hand every time. since im at the most basic of beginner levels, im sure its very simple and im just overlooking something. if any of you could take a look at this script and tell my why this doesnt work, id appreciate it. 1 - when I make an update, it saves to a different file and if you make more that one update, the database starts making new entries rather than editing the existing one. 2 - the HTML output is what it should look like. but i cant figure out how to make it loop through and print a line for each entry according to rank. Thanks in advance. Here is the script: #!/usr/local/bin/perl ###################################################################### # This program checks my email box via POP3, then get the updates # from the emails. then run the numbers, then output to a text file # of the HTML that I can then cut/paste to the site. Easy. ###################################################################### #declatations (cuz im a VB guy) # this actually came from an email from the form. #NewPass: new password, if they want one, if there is nothing here, then ignore this variable #TIME: 1011637980 This is totally irrelevent. Ignore this #Email: [EMAIL PROTECTED] #InGA: 3 - this is the goals allowed in the game you are adding to your stats #InIR: Roller - was this a roller game, or an ice game #Ingoalie: mike - the user name of the person updating thier stats #Inpass: potato - Password, must match password in database #Inwlt: clearMeOut - Win = A win, Loss = A loss, Tie = a tie, clearMeOut = clear all stats for new season. ######## variables in DB #GA = goals allowed #IR = ICE or ROLLER #Goalie = name as it appears on the website #Password = Password #Wlt = Win, Loss, Tie, or clear #chapter = Which chapter of the brotherhood you are in #username = the goalies user name #rank = rank based on GAA. lowest GAA will be ranked 1 though highest GAA ranked whatever the highest is #Variables in the list #@stats = ('Goalie', 'chapter', 'GP', 'W', 'l', 'T', 'SO', 'GAA', 'GA', 'Password', 'Rank', 'Username') #Positions = 0 1 2 3 4 5 6 7 8 9 10 11 # master Db's # %mastercombined [ ] # %masterice [ ] # %masterroller [ ] # The name of the total (ice and roller) combined database file # $CDB = 'goaliestats.txt'; $CDB = 'goaliestatstest.txt'; # The name of the Ice database file $IDB = 'icegoaliestats.txt'; # The name of the roller database file $RDB = 'rollergoaliestats.txt'; ################################################## ## Open email and get info from update messages ## ################################################## # I will do this when I get the actual program working ################################################################### ## Get Stats From User (Becomes obsolete when email input works ## ## see above) ## ################################################################### ### ask if they want to enter or quit. while(1) { # Loop forever print "\nDo you want to Enter a new stat (E), " . " or quit and print (Q): "; $DoSearch = <STDIN>; chomp($DoSearch); $DoSearch =~ tr/A-Z/a-z/; # Check if they want to quit if($DoSearch eq 'q') { last } # Check if they did *not* say e or E unless($DoSearch eq 'e') { print "You must enter either E or Q.\n"; next; # Go out to the while loop } ### ask if the game was Ice or Roller. print "\n(I)ce or (R)oller Game: "; $InIR = <STDIN>; chomp($InIR); $InIR =~ tr/A-Z/a-z/; # if uppercase, change to lowercase ### ask what goalie. print "\nEnter Goalie username: "; $Ingoalie = <STDIN>; chomp($Ingoalie); $Ingoalie =~ tr/A-Z/a-z/; # if uppercase, change to lowercase ### ask For password print "\nEnter Goalie Password: "; $Inpass = <STDIN>; chomp($Inpass); $Inpass =~ tr/A-Z/a-z/; # if uppercase, change to lowercase ### ask Win Loss or Tie. print "\n(W)in, (L)oss, (T)ie, or (C)lear: "; $Inwlt = <STDIN>; chomp($Inwlt); $inwlt =~ tr/A-Z/a-z/; # if uppercase, change to lowercase ### ask how many Goals allowed. print "\nGoals allowed: "; $InGA = <STDIN>; chomp($InGA); ######################################## ## Get Original Numbers from Database ## ######################################## # Open the database file but quit if it doesn't exist open(INDB, $CDB) or die "The database $CDB could " . "not be found.\n"; # Loop through the records in the file while(<INDB>) { $TheRec = $_; #chomp($TheRec); push (@mastercombined, $TheRec); } # End of while(<INDB>) ####################################### ## Run Numbers, figure out new stats ## ####################################### #### match username to proper DB entry # Go to the top of the database in case this isn't # the first time they are searching seek(INDB, 0, 0); # Loop through the records in the file while(<INDB>) { $TheRec = $_; chomp($TheRec); ($Goalie, $chapter, $GP, $W, $l, $T, $SO, $GAA, $GA, $Password, $Rank, $Username) = split(/\t/, $TheRec); if($Username eq $Ingoalie) { @stats = ($Goalie, $chapter, $GP, $W, $l, $T, $SO, $GAA, ,$GA, $Password, $Rank, $Username); # enter all vars into @stats print "\nOrder:Goalie, chapter, GP, W, l, T, SO, GAA, GA, Password, Rank, Username"; #for reference, print "\nold stats: @stats\n"; #for reference, to test and test update later } # End of if } # End of while(<INDB>) #### Check password. (not necessary unil updated directly from Email) #### GP (games played) goes up by one @stats[2] = @stats[2] + 1; #### W L or T (win, Loss or Tie) goes up by one if($Inwlt eq 'w') { @stats[3] = @stats[3] + 1 } if($Inwlt eq 'l') { @stats[4] = @stats[4] + 1 } if($Inwlt eq 't') { @stats[5] = @stats[5] + 1 } #### GA (goals against) goes up by user entered number @stats[8] = @stats[8] + $InGA; #### if goals allowed = 0 then shutouts goes up by one. if($InGA eq '0') { @stats[6] = @stats[6] + 1 } #### New GAA figured @stats[7] = @stats[8] / @stats[2]; #### if 'clear', set combined stats to 0 if($Inwlt eq 'c') { @stats[2] = 0; #GP @stats[3] = 0; #W @stats[4] = 0; #L @stats[5] = 0; #T @stats[6] = 0; #SO @stats[7] = 0; #GAA @stats[8] = 0; #GA } # end if $Inwlt = 'c' #### if new password, update to password file file (also not necessary utill I get it to update directly from email) ################################## ## Save new numbers to Database ## ################################## #### Determine which record we updated $splicecount = 0; # Go to the top of the database seek(INDB, 0, 0); # Loop through the records in the file while(<INDB>) { $TheRec = $_; chomp($TheRec); ($Goalie, $chapter, $GP, $W, $l, $T, $SO, $GAA, $GA, $Password, $Rank, $Username) = split(/\t/, $TheRec); if($Username eq $Ingoalie) { $splicethis = $splicecount ; } # End of if $splicecount = $splicecount + 1; } # End of while(<INDB>) # Close the database (read) file but quit if it doesn't exist close(INDB) or die "The database $CDB could not be found.\n"; # Open the database (Write) file but quit if it doesn't exist #using test db goaliestatstest.txt untill fully tested open(INDB,'>$CDB'); #### Update master DB splice (@mastercombined, $splicethis, 1, (@stats[0], ' ',@stats[1], ' ',@stats[2], ' ',@stats[3], ' ' ,@stats[4], ' ',@stats[5], ' ',@stats[6], ' ',@stats[7], ' ',@stats[8], ' ',@stats[9], ' ' ,@stats[10], ' ',@stats[11], ' ')); #### rank (sort) by GAA #find Lowest GAA #enter new rank as #1 #find next lowest GAA #enter new rank as #2 #loop though untill all ranks are updated #### Save Stats print INDB @mastercombined; ####Report Stats saved print "\nnew stats: @stats\n"; #for reference, to test that the update went through correctly print "\nSAVED.\n"; # Close the database (write) close(INDB); ############################################ ## Get Original Numbers from I/R Database ## ############################################ # cut and paste the code from the total combined Database update, but alter it to work only on Ice or Roller # depending on which one applies ############################################################# ## Run Numbers, figure out new stats For ICE or ROLLER## ############################################################# #### match username to proper DB entry # if it does not exist for user, create it. they were already # verified in the combined database #### GP goes up by one #### W L or T goes up by one #### GA goes up by user entered number #### if goals allowed = 0 then shutouts goes up by one. #### New GAA figured #### if 'clear', delete I/R entries #### if new password, update file ###################################### ## Save new numbers to I/R Database ## ###################################### # cut and paste the code from the total combined Database update, but alter it to work only on Ice or Roller # depending on which one applies ################################################# ## Write new numbers with HTML format for site ## ################################################# } # end of main loop that keeps asking to enter stats or quit #### Date last updated #### Combined (this is what the output should look like. this is just here as an example because #### right now it simply prints what it is told. In an ideal world, it will loop though the datatbase #### and print each line untill the Database has no more records. How the hell do I do that?? #################################################################################### #Print the beginning of the HTML output. This part will not change #################################################################################### print "\n\n"; print '<TABLE BORDER="3" CELLSPACING="1" CELLPADDING="1">'; print "\n\n"; print "<TR>\n"; print '<TD ALIGN="center" COLSPAN="9"><B> TOTAL </B>'; print "\n\n"; print "<TR>\n"; print "<TD><B><U> Rank </B></U></TD>\n"; print "<TD><B><U> Name </B></U></TD>\n"; print "<TD><B><U> GP</B></U> </TD>\n"; print "<TD><B><U> W</B></U> </TD>\n"; print "<TD><B><U> L </B></U></TD>\n"; print "<TD><B><U> T </B></U></TD>\n"; print "<TD><B><U> SO </B></U></TD>\n"; print "<TD><B><U> GAA</B></U> </TD>\n"; print "</TR>\n"; print "\n"; #################################################################################### # begin loop thu adding the different Players, here is how dan would look. (again, this is an example # of one line, I cant figure out how to make it loop and print this for each player) #################################################################################### # find rank 1 and print print "<TR>\n"; print "<TD> 1 </TD>\n"; print "<TD> Dan #61 </TD>\n"; print "<TD> 12 </TD>\n"; print "<TD> 7 </TD>\n"; print "<TD> 5 </TD>\n"; print "<TD> 0 </TD>\n"; print "<TD> 2 </TD>\n"; print "<TD> 3.00 </TD>\n"; print "</TR>\n"; print "\n"; # do again untill all players are printed ############################################################### #now print the end of the table, this line will not change ############################################################### print "</TABLE>\n\n"; #### Ice # do the same thing again for the Ice Data base #### Roller #do the same thing again for the roller database print "Program finished.\n"; ===== The Goalie Brotherhood: http://www.goaliebrotherhood.com __________________________________________________ Do You Yahoo!? Yahoo! Sports - Coverage of the 2002 Olympic Games http://sports.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]