列内の複数の名前が何をFAMILYTAG
示しているかは明確ではありませんが、別の姓であると仮定してまとめました.
use strict;
use warnings;
my %names;
my %families;
while (<DATA>) {
next unless /^\d/;
my ($id, $name, $familytag, $effect) = split /\t/;
for my $tag (split /,/, $familytag) {
push @{ $names{$name} }, $tag;
push @{ $families{$tag} }, $name;
}
}
while () {
print "\nName: ";
chomp (my $name = <>);
last unless $name =~ /\S/;
print "\n";
if (my $tags = $names{$name}) {
for my $tag (@$tags) {
my $names = $families{$tag};
next unless @$names > 1;
printf "%s %s\n", $_, $tag for @$names;
}
}
else {
warn qq(No name "$name" found);
}
}
__DATA__
ID NAME FAMILYTAG EFFECT
001 John Black Positive
002 Kate Rhodes,Mich Positive
003 Aaron Sunders Negative
004 Shirley Rhodes Negative
005 Dexter Sunders,Hark Positive
出力
E:\Perl\source>ff.pl
Name: Kate
Kate Rhodes
Shirley Rhodes
Name: Aaron
Aaron Sunders
Dexter Sunders
Name: Mike
No name "Mike" found at E:\Perl\source\ff.pl line 31, <> line 3.
Name: Dexter
Aaron Sunders
Dexter Sunders