Most Respected Masters,
Given this HoHoA
my %HoHoA = ( 'set1' => { 'key1_set1' => [ 'some arrays' ], 'key2_set1' => [ 'some arrays' ], }, 'set2' => { 'key1_set2' => [ 'some arrays' ], 'key2_set2' => [ 'some arrays' ], }, 'set3' => { 'key1_set3' => [ 'some arrays' ], 'key2_set3' => [ 'some arrays' ], }, 'set4' => { 'key1_set4' => [ 'some arrays' ], 'key2_set4' => [ 'some arrays' ], 'key3_set4' => [ 'some arrays' ], }, );
How can I get this:
key1_set1 - key1_set2 key1_set1 - key2_set2 key1_set1 - key1_set3 key1_set1 - key2_set3 key1_set1 - key1_set4 key1_set1 - key2_set4 key1_set1 - key3_set4 key2_set1 - key1_set2 key2_set1 - key2_set2 key2_set1 - key1_set3 key2_set1 - key2_set3 key2_set1 - key1_set4 key2_set1 - key2_set4 key2_set1 - key3_set4 ... key1_set3 - key1_set4 key1_set3 - key2_set4 key1_set3 - key3_set4 key2_set3 - key1_set4 key2_set3 - key2_set4 key2_set3 - key3_set4
What I aim to do is to get pairs of secondary keys that don't come from the same primary key. And once they are evaluated they don't need to be evaluated again. I hope my example above is clear.
Also note that the size of the HoHoA may vary. Now it is 4 (from "set1" to "set4") other case maybe 10 (from "set1" to "set10"), etc. My best attempt is this which is still far from correct:
foreach my $set ( sort keys %HoHoA) { print "$set\n"; my @key = keys %{$HoHoA{$set}}; for ( my $i = 0; $i<@key; $i++ ) { for (my $j=$i+1; $j<@key; $j++ ) { print "$key[$i] - $key[$j]\n"; } } } # Am I attacking the problem correctly?
Sorry I really don't have a strong background in Computer Science. Please be patient with me.

In reply to Getting Pairs of 2nd-ary Keys in HoHoA by neversaint

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.