I didn't quite understand the format spec and the difference between the '/' and ','.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.