Again it is a matter of building a map from one file then looking up the map while parsing the second file. Consider:

use strict; use warnings; my $rawData = <<'RAW'; chr1q21 na S100A3 S100A6 HRNR DRD5P2 EFNA1 HSA04910_INSULIN_SIGNALING_PATHWAY na XRCC5 HRAS V$YY1_02 na B3GALT6 DZIP1 RAB1B SART3 FLJ20309 MORF_EIF3S2 na HCCS XRCC3 LDHB LDHA OXA1L RPL14 module_486 na CYP3A7 C14orf179 JAG2 INTS1 RBM6 CATABOLIC_PROCESS na PGD HNRPD USE1 RNF217 RNASEH1 RAW my $mapData = <<'MAP'; XRCC5 SNP_A-1966881 1 EFNA1 SNP_A-1877994 9 HRNR SNP_A-1919060 2 XRCC5 SNP_A-1966884 1 XRCC5 SNP_A-1966882 1 HRNR SNP_A-1829030 1 MAP my %geneMap; open my $mapIn, '<', \$mapData or die "Failed to open map data: $!"; while (<$mapIn>) { chomp; my ($gene, @data) = split; next unless exists $data[1] || exists $data[2]; # Skip if unexpect +ed data format $geneMap{$gene}{$data[0]} = $data[1]; } close $mapIn; open my $rawIn, '<', \$rawData or die "Failed to open raw data: $!"; while (<$rawIn>) { chomp; my ($geneset, $ignore, @genes) = split; next unless @genes; # Skip empty or badly formed line print "$geneset\n"; for my $gene (@genes) { next unless exists $geneMap{$gene}; print "\t$gene\t$_\t$geneMap{$gene}{$_}\n" for sort keys %{$geneMap{$gene}}; } } close $rawIn;

Prints:

chr1q21 HRNR SNP_A-1829030 1 HRNR SNP_A-1919060 2 EFNA1 SNP_A-1877994 9 HSA04910_INSULIN_SIGNALING_PATHWAY XRCC5 SNP_A-1966881 1 XRCC5 SNP_A-1966882 1 XRCC5 SNP_A-1966884 1 V$YY1_02 MORF_EIF3S2 module_486 CATABOLIC_PROCESS

Perl is environmentally friendly - it saves trees

In reply to Re: Searching each word of a file by GrandFather
in thread Searching each word of a file by biomonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.