title: printing all lines when multiple matching values in table perl
body: <p>I have two tables: $conversion and $table. In my script I'm checking if there is a match between cols[5] from $conversion and cols[2] from $table, if this is the case I print out the value from another column in $conversion, namely the corresponding value in cols[1].</p>
  
  <p>This is all working fine.</p>
  
  <p>However some values in cols[5] from $conversion are the same. If this is the case I want to print off course everything from $conversion that matches. Now he prints only the corresponding value for the last match that he finds while going through the file. So when cols[5] from $conversion contains 4 times the same value, in the output only the corresponding value of the 4th match is printed. Any hint on how to solve this?</p>
  
  <p>This is my script:</p>
  
  <pre><code>my %hash = ();
  while (&lt;$conversion&gt;) {
      chomp;
      my @cols = split(/\t/);
      my $keyfield = $cols[5];
      my $keyfield2 = $cols[1];
      $hash{$keyfield} = $keyfield2;
  }
  seek $table,0,0;   #cursor resetting
  while (&lt;$table&gt;) {
      my @cols = split(/\t/); 
      my $keyfield = $cols[2]; 
      if (exists($hash{$keyfield})) {
          print $output "$cols[0]", "\t", "$hash{$keyfield}", "\t", "$cols[1]\n";
      }
  }
  </code></pre>