The opening comment line (purpose of script) is a VERY good
thing - keep that habit, and always start each new script
with such commentary. Then, before writing the actual code,
expand the comment to explain briefly how the program will
accomplish the purpose. (Many times, the commentary may be
as long as the code, or longer -- that can be a Good Thing.)
For example:
# First, read the long list of players and scores into a hash
# Then, read the short list of important players, and print
# their scores from the hash
open( LIST, "score" ) || die "can't open score file\n";
while (<LIST>) {
chomp;
($name,$score) = split(/,/);
$scores{$player} = $score;
}
open( TEAM, "player" ) || die "can't open player file\n";
while (<TEAM>) {
chomp;
print "$scores{$_} $_\n";
}
There are ways to write the code more compactly, of course.
Is there any chance of two different teams having players
named "John Smith" or some such? This would make it more
challenging -- the large "score" file would need to be
structured to make it clear who's on each team, and you
would need to use that structure when reading it. (But then,
if you're actually just interested in members of a chosen
team, then you don't need a file listing that set of names --
you just need the name of the team.)
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.