|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
I'm trying to design a script that generates NBA standings from inputted scores. In addition to win/loss records, I want to keep track of division and conference records. So I have several arrays that include the teams that fall under each catetgory:
@teams - All teams @east/@west - By conference @pacific, @midwest, @central, @atlantic - By division How can I say "if Team A is in @pacific and Team B is in @pacific and Team A's score is higher than Team B, then add 1 to Team A's division wins and add 1 to Team B's division losses"? Any help would be greatly appreciated. Thanks! Mike |
|
#2
|
|||
|
|||
|
Hi there
Interesting so I gave it a bash, it should work in theory There are two ways first using a data base with associative arrays, and then just with arrays Try making the divisions Associative arrays or hasehes so that you can pull the value team A out of the array #these are from the input form $score = q->param("score"); $score1 = q->param("score1"); $team = q->param("team"); $team1 = q->param("team1"); #an array to associate the team with the score %teamscore_array($team,$score,$team1,$score1) $teamscore = @teamscore_array{$score} $teamscore1 = @teamscore_array{$score1} #one array for all the teams associated with the divisions %division('globe troters', divA,'the magic',divA,'lakers',divB,'bears',divC)#etc #this gets the teams division $teamdivision = @division{$team} $teamdivisoin1 = @division($team1} #this checks if they are in the same division and adds +1 to the winning team in the data base if ($teamdivision eq $teamdivision1) {if ($teamscore > $teamscore1) {#add 1 to $team in division $teamdivision in your database} else {#add 1 to $team1 $teamdivision in your database} } or if you want to stick with arrays, make an associative array with the team names and their current scores %teamsandscores_array('the magic',10,'jazz',20)#etc #this gets the winning team if ($teamscore > $teamscore1) {$winningteam = $team} else{$winningteam = $team1} #this updates the winning teams score $teamsandscores_array{$winningteam}(+1) I havent used the array method before but in theory it should work use the logic for the rest Good luck [This message has been edited by chrisdice4 (edited October 27, 2000).] [This message has been edited by chrisdice4 (edited October 27, 2000).] |
|
#3
|
|||
|
|||
|
Thanks for the tip! I was able to determine conference, division, home, away, overtime, and overall wins and losses. Thanks again!
Mike |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > checking for value in an array |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|