The program died when attempting to open the ranks.txt file
(line 69). You should modify your code so that if the file
doesn't exist (hence it is a /New File/) you create and
initialize it accordingly.
Once I've entered the required input the program ends and
does not print any output to the screen. It writes
to the rank.txt file:
---------------------------------------
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.