However I figure that a hash table is the right idea. For your enjoyment and comments...
#!/usr/bin/perl -w use strict; my %name2team; #eg Phil => Team1, Team4 my %team2name; #eg Team1 => Joe Phil Amenda my $line= ""; while ($line = <DATA> ) { next if $line =~ /^\s+$/; #skip blank lines $line =~ s/[=,\/\s+]/ /g; #make spaced based tokens my ($team, @names) = split /\s+/, $line; foreach my $name (@names) { push @{$name2team{$team}},$name; push @{$team2name{$name}},$team; } } foreach my $team (sort keys %name2team) { print "$team has: @{$name2team{$team}}\n"; } print "\n"; #just a spacer line foreach my $name (sort keys %team2name) { print "$name is on: @{$team2name{$name}}\n"; } =output of the above: Team1 has: Joe Phil Amenda Team2 has: James Pam Joe Team3 has: Carmen Lisa James Team4 has: Don Phil Carmen Team5 has: Uri Kate Don Amenda is on: Team1 Carmen is on: Team3 Team4 Don is on: Team4 Team5 James is on: Team2 Team3 Joe is on: Team1 Team2 Kate is on: Team5 Lisa is on: Team3 Pam is on: Team2 Phil is on: Team1 Team4 Uri is on: Team5 =cut __DATA__ Team1=Joe / Phil , Amenda Team2 = James / Pam, Joe Team3= Carmen , Lisa / James Team4=Don , Phil / Carmen Team5=Uri , Kate / Don
In reply to Re: Matching problem
by Marshall
in thread Matching problem
by jo26
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |