1
我有两个表。第一个是$sample
,看起来像这样:使用多个值作为Perl散列中的键值
col1 col2
A 1
A 3
A 4
B 7
... ...
第二个是$exon
,看起来像这样:
col1 col2 col3 col4 col5
name1 A 1 100 200
name2 A 2 300 400
name3 A 3 500 600
name4 A 4 700 800
我想检查是否有来自$sample
和col2
和col1
和col2
之间的匹配col3
from exon
。
我通常在Perl中使用哈希值。我知道它是如何工作的,当你只是寻找两列之间的匹配。但我现在卡住了,因为来自两列的值应该匹配。这就是我对现在
my %hash =();
while(<$sample>){
chomp;
my @cols = split(/\t/);
my $keyfield = $cols[0]; #col1
my $keyfield2 = $cols[1]; #col2
push @{ $hash{$keyfield}}, $keyfield2}; #this is probably not correct
}
seek $exon,0,0; #cursor resetting
while(<$exon>){
chomp;
my @cols = split(/\t/);
my $keyfield = $cols[1]; #col2
my $keyfield2 = $cols[2]; #col3
if (exists($hash{$keyfield}) && exists($hash{$keyfield2})) {
print $output $cols[0], "\t", $cols[3], "\t", $cols[4], "\n";
}
}
@Downvoter:请解释。 – Jens