Another approach would be to use the hash both as a lookup table to filter on relevant entries (as already suggested by others), and to collect the results by $gene_id (which I guess was the idea behind looping through the file multiple times — assuming the data in IN aren't necessarily already sorted by ID). Something like this:
while(<INlist>){ chomp; $scGeneids{$_} = ""; } ... while (<IN>){ chomp; my @columns=split /\t/; my $gene_id=$columns[0]; my $SNP_pos=$columns[2]; if ( exists $scGeneids{$gene_id} ){ $scGeneids{$gene_id} .= "$gene_id\t$SNP_pos\n"; # collect by +ID } } for my $key (sort keys %scGeneids) { print OUT $scGeneids{$key}; }
In reply to Re: help with loop
by Eliya
in thread help with loop
by AWallBuilder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |