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:
my %players; for (<DATA>) { chomp; my ($team) = m!^ (.+?) = (?<left>.+?) \s*/\s* (?<right>.+) $!x or die "Line `$_' doesn't match"; for my $side (qw<left right>) { $players{$_}{$side} = $team for split m!\s*[,/]\s*!, $+{$side} +; } } # Remove players only on one team delete @players{ grep { keys %{$players{$_}} == 1 } keys %players }; local $" = ' AND '; print "$_ IS IN @{$players{$_}}{qw<left right>}\n" for keys %players;
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'].
my %players; for (<DATA>) { chomp; my ($team,$players) = split /=/; push @{$players{$_}}, $team for split m!\s*[,/]\s*!, $players; } delete @players{ grep { @{$players{$_}} == 1 } keys %players }; local $" = ' AND '; print "$_ IS IN @{$players{$_}}\n" for keys %players;
In reply to Re: Matching problem
by rjt
in thread Matching problem
by jo26
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |