Thank you for your comment.
I ran the code with 'use strict' and '-w' (including a 'use vars' statement at the top) and it ran and compiled and whatnot successfully. I probably should have clarified, but some problems that I noticed witht the output was this:
(1)The first output works correctly, except a blank line is added at the top (could it make an error in my logic?)
(2)THe second(and third and etc.) time it is not correct. Namely, when I enter the data and give the team number, if I have given the team numbers as 1 2 3 and 4, and I enter 1, it does not prompt me for the names(this is correct, because I would already have them) BUT for 2 3 and 4 it incorrectly prompts me for their names; also, the output is erroneous. Namely the last part of it (the number of matches) stays at 1, i.e., does not increase to 2 (3, 4, etc.) as it should. Also it doesn't average the score, or remember the names.
Sample input for the program would be this, if it helps:
11 . 2 . 3 . 2 . 92 . 0 . 0 . 0 . 0 . 0 . 1 . name1 name2 . 2 . name3 name4 . 3 . name5 name6 . 4 . name7 name8 . <END OF INPUT>
The score would be 732 (as it correctly displays); but if you enter the SAME data again, it works incorrectly (and if you change the 11, let us say, to a 10, you can see that the scores don't average either).
As for the "calculations" I don't think you need to know them, becuase (I may not have made it clear) but they DO work. . . it is the actual ranking that does not. I have tested them (in the original C++ they were written in, albeit) and they work fine.
If any more info is needed, just ask. | [reply] |
---------------------------------------
1:244:244:andy ben:1
<>
2:244:244:cathy doug:1
<>
3:244:244:elaine fred:1
<>
4:244:244:gail harry:1
---------------------------------------
I'm not sure where you came up with 732, it is not
displayed anywhere that I can see. Just because something
was coded in C++ doesn't mean that it will work correctly
after you convert it to Perl. If your plan is to
read in each team's data and then do calculations and write
the info back out to the file, you should use logic along
these lines:
if rank.txt exists {
if rank.txt is not empty {
read each team's info and store in an array/hash
}
}
if user wants to add new team data {
loop # once through loop gets only data for one team
get* team number
get* member names
get* team scores/whatever
append record to rank.txt
endloop
# * input/store to array/hash
}
perform calculations for array/hash
print results
More observations:
- A common mistake for programmers is to type in a
complete program and then try to debug it. Your code should
be developed in small chunks. For example, don't attempt to
code subs to perform calculations when you haven't even
debugged/verified your input routines yet. Your chunk size
may vary depending on the complexity of a given code segment.
- Use print liberally when verifying code correctness.
You can always comment them out later.
- Start by commenting out your all of your subroutine
calls. As you successfully debug one chunk, uncomment the
next.
--Jim
| [reply] [d/l] [select] |