The stupid question is the question not asked | |
PerlMonks |
Re: Matching problemby rjt (Curate) |
on Sep 09, 2013 at 01:14 UTC ( [id://1052948]=note: print w/replies, xml ) | Need Help?? |
Edit: I misunderstood the left/right requirement in my first pass. (Are Mulligans permissible with these teams?) Here's a version that's hopefully much closer to what you want:
The logic is relatively straightforward. For each line, parse the team, left, and right strings or die trying, and then split the left and right chunks into left/right. We are then left with, for example, $players{Don} = { left => 'Team4', right => 'Team5' };. After that, we can delete any player who has only 1 key in their hash, as they are only on left or right, and not both. I'll leave my original misguided answer below the readmore tag. As I understand it, your goal is to get a list of players who are assigned to more than one team, correct? The teams have a left/right side which I don't understand, but I would guess that a player can't be on the same team more than once, so checking whether they're on the team at all is sufficient? Here's my approach, which splits each line and puts every player on the team into the %players hash. Because you're only interested in duplicates, we then delete the players who are only on one team. Finally, a trivial loop to print the results. Don's entry in the %players hash would look like $players{Don} = ['Team4', 'Team5'].
use strict; use warnings; omitted for brevity.
In Section
Seekers of Perl Wisdom
|
|