Hi all, I am very new to perl, actually just start handling hash, here is a problem I'd really need some help:

Basically I have two hashes. Hash1 has keys and values, for each value, it contains elements separated by ",". By splitting each of the value, the elements would be keys that can be found in the Hash2. What I want is to obtain the values in the Hash2 to be assigned to each of the corresponding keys in Hash1.

For example

%Hash1=(

'key1', 'val1,val2',

'key2', 'val3')

for each value in Hash1, it can be split by ",", then val1 and val2 are individual keys can be found in Hash2, and val1 as key in Hash2 has values (val5,val6, val7), val2 as key in Hash2 has values (val8 and val9) and so on. e.g.

%Hash2=(

'val1','val5,val6,val7',

'val2','val8,val9',

'val3','val3')

I would like to obtain a result as:

%newhash=('key1','val5,val6,val7,val8,val9',

'key2','val3')

that is that the keys in Hash1 have all corresponding values in Hash2

my problem is that I cannot put values for val1 and val2 together for key1.

Any suggestions are greatly appreciated.


In reply to how to use the values of the first hash to be the keys for the second hash by lrl1997

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.