hash - perl compare files using hashes with multiple keys -
hash - perl compare files using hashes with multiple keys -
i have next script compare columns 2 files using hash.
but when there match between cols[5] $conversion , cols[2] $table, want print out value column in $conversion, namely corresponding value in cols[1]. i've tried assigning value cols[1] sec key in %hash, called $keyfield2. don't succeed in printing it. code far:
my %hash = (); while(<$conversion>){ chomp; @cols = split(/\t/); $keyfield = $cols[5]; $keyfield2 = $cols[1]; $hash{$keyfield,$keyfield2}++; } seek $table,0,0; #cursor resetting while(<$table>){ @cols = split(/\t/); $keyfield = $cols[2]; if (exists($hash{$keyfield})){ print $output "$cols[0]","\t","$hash{$keyfield2}","\t","$cols[1]\n"; } }
any hints on how this?
is there reason utilize hash reference. hash seek this:
my $keyfield = $cols[5]; $keyfield2 = $cols[1]; $hash{$keyfield} = $keyfield2
and print to:
print $output "$cols[0]","\t","$hash{$keyfield}","\t","$cols[1]\n";
perl hash
Comments
Post a Comment