http://qs321.pair.com?node_id=247571

dirtyboy has asked for the wisdom of the Perl Monks concerning the following question:

The perl program should accept a file name as a command line argument of the form:
Karpov Shirov 3.5-1.5 Shirov Anand 2.0-3.0 Anand Kasparov 1.0-4.0 Kasparov karpov 2.0-2.0 BlueJunior Kasparov 3.0-3.0
The first two strings are names of chess players, followed by the score of the match between them. For example, in the first match Karpov beat Shirov by a score of 3.5 to 1.5.

Your program should read these data and create an associative array, record, indexed by player names. In record{'name'}, you should store the number of wins, losses and draws of player name.

Your program should then produce output for each player, in the form:

player_name, # of wins, # of losses, # of draws and the output should be sorted in descending order of total points.

Note : A player gets 1 point for each win, 0 points for a loss, and 0. +5 points for a draw. *********************************************** THIS FOLLOWING IS THE CODE THAT I HAVE WRITTEN. UW PICO(tm) 4.0 File: red.pl $in_file = shift@ARGV; open(PLAYERS, "<$in_file") || die "Cannot open the input file!"; $p1wins = 0; $p1loss = 0; $p2wins = 0; $p2loss = 0; $p1draw = 0; $p2draw = 0; $wins = 0; $loss = 0; $draw = 0; while(<PLAYERS>) { if (/(\w+)\s+(\w+)\s+(\d\.\d)\-(\d\.\d)/) { if($3 > $4) { $p1wins = $p1wins + 1; $p2loss = $p2loss + 1; $player{$1} = [$1, $p1wins, $p1loss, $p1draw]; $player{$2} = [$2, $p2wins, $p2loss, $p2draw]; } } elsif($3 < $4) { $p1loss = $p1loss + 1; $p2wins = $p2wins + 1; $player{$1} = [$1, $p1wins, $p1loss, $p1draw]; $player{$2} = [$2, $p2wins, $p2loss, $p2draw]; } else { $p1draw = $p1draw + 1; $p2draw = $p2draw + 1; $player{$1} = [$1, $p1wins, $p1loss, $p1draw]; $player{$2} = [$2, $p2wins, $p2loss, $p2draw]; } } } print $player{Kasparov}[0], " ",$player{Kasparov}[1], " ",$player{Kasp +arov}[2]," ",$player{Kasparov}[3],"\n"; print $player{Anand}[0]," ",$player{Anand}[1]," ",$player{Anand}[2]," +",$player{Anand}[]3,"\n"; print $player{Karpov}[0], " ",$player{Karpov}[1], " ",$player{Karpov}[ +2]," ",$player{Karpov}[3],"\n"; print $player{Shirov}[0], " ",$player{Shirov}[1], " ",$player{Shirov}[ +2]," ",$player{Shirov}[3],"\n"; print $player{BlueJunior}[0], " ",$player{BlueJunior}[1], " ",$player{ +BlueJunior}[2]," ",$player{BlueJunior}[3],"\n"
I am really stuck with this, I am not able to get past this. Your help is greatly appreciated.

Thanks.
Arjun.

+ 2loss, $p2draw]; } )

Edit by tye, add formatting