【发布时间】:2014-11-07 09:51:58
【问题描述】:
我有以下脚本,我使用哈希比较两个文件中的列。
但是当 $conversion 中的 cols[5] 和 $table 中的 cols[2] 匹配时,我想打印出 $conversion 中另一列的值,即 cols[1] 中的对应值。我试图通过将 cols[1] 中的值分配给我的 %hash 中的第二个键,称为 $keyfield2 来做到这一点。但我没有成功打印它。到目前为止,这是我的代码:
my %hash = ();
while(<$conversion>){
chomp;
my @cols = split(/\t/);
my $keyfield = $cols[5];
my $keyfield2 = $cols[1];
$hash{$keyfield,$keyfield2}++;
}
seek $table,0,0; #cursor resetting
while(<$table>){
my @cols = split(/\t/);
my $keyfield = $cols[2];
if (exists($hash{$keyfield})){
print $output "$cols[0]","\t","$hash{$keyfield2}","\t","$cols[1]\n";
}
}
关于如何做到这一点的任何提示?
【问题讨论】: