Following up on my earlier post Merging Files: A Different Twist...

I have a program which takes a structured format file and reports back data contained in specified fields.

eg: exfields.pl file.gz field1,field2,field3
which produces the following output:
steve 37 ma jeff 35 ca ben 30 tn
I am trying to write a program which will merge 2 such files. file_1.gz and file_2.gz each contain different data associated with "steve", "jeff", ben", and I want to merge the output of both files, and display the end result to the user. output of:  exfields.pl file_1.gz field1,field2:
steve 37 ma jeff 35 ca ben 30 tn
output of: exfields.pl file_2.gz  field1:
steve guitar jeff bass ben drums
after both files are merged needs to become:
steve 37 ma guitar jeff 35 ca bass ben 30 tn drums
The first approach I considered (yes, I'm very new to Perl) with was creating 2 separate arrays and then joining them, only to realize that this would not accomplish my task. Tried all day, until now to:
merge.pl file1 field,field file2 field
which extrapolates:
file1 field,field
pass it through a subroutine that would produce a hash containing:
%hash_1 = steve => '37' AND 'ma' jeff => '35' AND 'ca' ben => '30' AND 'tn'
then extrapolates:
file2 field
pass it through the same subroutine, which would produce a hash containing:
%hash_2 = steve => 'guitar' jeff => 'bass' ben => 'drums'
oh yeah, I am NOT trying to code this program as it appears; rather I am only trying to demonstrate what I am tring to do. I have the extrapolations that I referred to already coded. I also know how to produce %hash_2. My question is how could I code the subroutine to do what I am trying to do? Before that consideration, am I correct in thinking that the above examples of hashes will produce my desired result? I have read several references to "hashes with keys that contain multiple values", and "references to arrays", but I can't seem to use the examples effectively. Please help, while I still have hair on my head. .

In reply to Merging 2 Formatted Files by Limo

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.