Okay, I'm a totally newb and feel really frustrated. I need to write a simple script to do the following.

Open a file that contains information in the following format:

385#19126!NM_167210@[1103;1104] 2 386#19127!NM_167211@[1103;1104] 2 387#19128!NM_167212@[1103;1104] 2 438#1781!NM_135492@[1337] 1 442#1794!NM_001042886@[1349] 1

What I need is each entry between ! and @ (e.g., NM_167210) to be associated with its corresponding number value at the very end....so in a hash, the key would be NM_167210 and the value would be 2, another key would be NM_167211 and the value would be 2.

I then have another file with each of the NM entries having a corresponding entry called CG*****:

CG32694-RD NM_167211 CG32694-RC NM_167210 CG32694-RA NM_167209 CG32694-RB NM_167212 CG33557-RA NM_001014730

So what I want is to process the first file as stated above, and then keep the association but convert the NM field into the CG fields and yet keep the corresponding value for the NM field. For example:

key 167211 with value 2 needs to be converted to corresponding CG32694-RD.

How do I go about doing this? I have no idea how to even start. A hash of arrays? An array of hashes? Just a regular hash? An array instead?

My problem is that there are so many ways to approach this. Do I use m// or split or grep or all three of them? The advantage of a hash is that it would associate each NM with its value, whereas in an array, I would lose the association, no?

Heeeeeeeeeeeeeeelp! I h*** PERL!


In reply to ISOLATE 2 ASSOCIATED FIELDS IN A TEXT FILE, then CONVERT the first into another based on a table of definitions by mupud

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.