这是解决代码,你可以学习一下:
die "perl $0 <in> <out>" unless(@ARGV==2);
open IN,"$ARGV[0]" or die "$!";
open OUT,">$ARGV[1]" or die "$!";
my%TE=();
while(<IN>){
chomp;
my @tmp=split(/\s+/);
if(exists $TE{$tmp[0]}){
$TE{$tmp[0]}=$TE{$tmp[0]}."\t$tmp[1]";
}else{
$TE{$tmp[0]}=$tmp[1];
}
}
close(IN);
for my$k(sort keys %TE){
print OUT "$k\t$TE{$k}\n";
}
close(OUT);