Dear all

I would like to load two tab-delimited text files into two separate hashes. These two files are in the following formats:

File 1

NM_001127328 202502_at NM_000018 200710_at NM_000019 205412_at NM_001111067 203935_at NM_000023 210632_s_at NM_000027 204332_s_at NM_000027 204333_s_at NM_000027 216064_s_at NM_000029 202834_at NM_000031 218487_at NM_000031 218489_s_at NM_000032 211560_s_at NM_000036 206121_at NM_000042 205216_s_at NM_000043 204780_s_at NM_000043 204781_s_at NM_000043 215719_x_at NM_000043 216252_x_at NM_000044 211110_s_at NM_000044 211621_at

File 2

204332_s_at P P A P P P P 216064_s_at P M P P P A A 211560_s_at P P P A P P P 200003_s_at P A P P P A P 211110_s_at P A P A P A P 200005_at P P A P P P A

First columns in both files serve as keys while the other columns are values. The problem with loading the first file into a hash is that it overwrites the values for the same keys. Is there a way to append the values for the same key hence creating single key - multiple values pairs?

Afterwards, I need to match each key in the first file with the each key in the second file through the values in the first file. I guess If I have a hash for the first file, then I can read through the second hash using three for loops.

Thank you,


In reply to Load a file into hash with duplicate keys by sophix

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.