我不清楚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