in reply to help with extracting data

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.)

Replies are listed 'Best First'.
Re: Re: help with extracting data
by graff (Chancellor) on Apr 16, 2002 at 06:20 UTC
    OOPS! Really sorry about that last bit of code I suggested... it should have read:
    ... ($name,$score) = split(/,/); $scores{$name} = $score; ... while (<TEAM>) { chomp; if (exists($scores{$_})) { print "$scores{$_} $_\n"; } else { print "$_ is not listed in score file\n"; } }