Hi Everyone I was hoping you might be able to help me with the following. I have 3 hashes and I want to iterate through the keys in each one and if I find a key that exists in all 3 hashes I want to then print out the corresponding values onto one line.

This is the content of hash one

bigstor14_mpt nnap5307-s bigstor17_mpt nnap5307-s bigstor12_mpt nnap5307-s bigstorq3_mpt nnap3289-s bigstor13_mpt nnap5307-s bigstor15_mpt nnap5307-s bigstor3_mpt nydevnfs_bigstor_volA bigstor4_mpt nydevnfs_bigstor_volA bigstor19_mpt nnap5307-s bigstor18_mpt nnap5307-s bigstorq4_mpt nnap3290-s bigstorderv_mpt nydevnfs_derv bigstor23_mpt nnap5307-s bigstor1_mpt nydevnfs_bigstor_volA bigstor5_mpt nydevnfs_bigstor_volA bigstor30_mpt nnap5307-s bigstor8_mpt nydevnfs_bigstor_volA bigstorq1_mpt nydevnfs_bigstorq1 bigstor10_mpt nnap5307-s bigstorqird_mpt nnap3290-s bigstorq2_mpt nydevnfs_bigstorq2 bigstor11_mpt nnap5307-s bigstorq0_mpt nydevnfs_bigstorq0 bigstor29_mpt nnap5307-s bigstor7_mpt nydevnfs_bigstor_volA bigstor20_mpt nnap5307-s bigstor16_mpt nnap5307-s bigstor21_mpt nnap5307-s bigstorsas_mpt nydevnfs_sas bigstor2_mpt nydevnfs_bigstor_volA bigstorn_mpt nydevnfs_bigstorn bigstormtg_mpt nydevnfs_mtge

This is the content of hash 2

bigstor14_mpt /vol/bigstor_volB/bigstor14 bigstor17_mpt /vol/bigstor_volC/bigstor17 bigstor12_mpt /vol/bigstor_volB/bigstor12 bigstorq3_mpt /vol/bigstorq3 bigstor13_mpt /vol/bigstor_volB/bigstor13 bigstor15_mpt /vol/bigstor_volB/bigstor15 bigstor3_mpt /vol/bigstor_volA/bigstor3 bigstor4_mpt /vol/bigstor_volA/bigstor4 bigstor19_mpt /vol/bigstor_volC/bigstor19 bigstor18_mpt /vol/bigstor_volC/bigstor18 bigstorq4_mpt /vol/bigstorq4 bigstorderv_mpt /vol/mtge bigstor23_mpt /vol/bigstor_volD/bigstor23 bigstor1_mpt /vol/bigstor_volA/bigstor1 bigstor5_mpt /vol/bigstor_volA/bigstor5 bigstor30_mpt /vol/bigstor_volB/bigstor30 bigstor8_mpt /vol/bigstor_volA/bigstor8 bigstorq1_mpt /vol/bigstorq1 bigstor10_mpt /vol/bigstor_volB/bigstor10 bigstorqird_mpt /vol/bigstor_ird bigstorq2_mpt /vol/bigstorq2 bigstor11_mpt /vol/bigstor_volB/bigstor11 bigstorq0_mpt /vol/bigstorq0 bigstor29_mpt /vol/bigstor_volB/bigstor29 bigstor7_mpt /vol/bigstor_volA/bigstor7 bigstor20_mpt /vol/bigstor_volC/bigstor20 bigstor16_mpt /vol/bigstor_volB/bigstor16 bigstor21_mpt /vol/bigstor_volC/bigstor21 bigstorsas_mpt /vol/sas bigstor2_mpt /vol/bigstor_volA/bigstor2 bigstorn_mpt /vol/bigstorn bigstormtg_mpt /vol/mtge

This is the content of hash 3

bigstor14_mpt /bb/bigstor14 bigstor17_mpt /bb/bigstor17 bigstor12_mpt /bb/bigstor12 bigstorq3_mpt /bb/bigstorq3 bigstor13_mpt /bb/bigstor13 bigstor15_mpt /bb/bigstor15 bigstor3_mpt /bb/bigstor3 bigstor4_mpt /bb/bigstor4 bigstor19_mpt /bb/bigstor19 bigstor18_mpt /bb/bigstor18 bigstorq4_mpt /bb/bigstorq4 bigstorderv_mpt /bb/bigstor/derv bigstor23_mpt /bb/bigstor23 bigstor1_mpt /bb/bigstor1 bigstor5_mpt /bb/bigstor5 bigstor30_mpt /bb/bigstor30 bigstor8_mpt /bb/bigstor8 bigstorq1_mpt /bb/bigstorq1 bigstor10_mpt /bb/bigstor10 bigstorqird_mpt /bb/bigstor_ird bigstorq2_mpt /bb/bigstorq2 bigstor11_mpt /bb/bigstor11 bigstorq0_mpt /bb/bigstorq0 bigstor29_mpt /bb/bigstor29 bigstor7_mpt /bb/bigstor7 bigstor20_mpt /bb/bigstor20 bigstor16_mpt /bb/bigstor16 bigstor21_mpt /bb/bigstor21 bigstorsas_mpt /bb/bigstor/sas bigstor2_mpt /bb/bigstor2 bigstorn_mpt /bb/bigstorn bigstormtg_mpt /bb/bigstor/mtgmodel

So for example I want to iterate through the keys in each hash and if the key bigstor14_mpt exists in all 3 hashes then I want to print out the corresponding values onto one line in an output file like this: nnap5307-s:/vol/bigstor_volB/bigstor14:/bb/bigstor14 Then continue the loop and if find another key that exists in all 3 hashes like for example bigstor17_mpt then grab the corresponding values from this key in each hash and then append to the output file the next line like this: nnap5307-s:/vol/bigstor_volC/bigstor17:/bb/bigstor17

I can sort the keys on one hash and print out the key/value pairs but I am really struggling with how to do the above. Please can you help me?


In reply to Comparing keys in 3 different hashes and if they are the same them print the values on one line by NewLondonPerl1

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.