in reply to help with extracting data
# 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.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: help with extracting data
by graff (Chancellor) on Apr 16, 2002 at 06:20 UTC |