As always, TIMTOWTDI :P
my @sets = sort(keys(%HoHoA)); while(@sets) { my $set1 = shift(@sets); foreach my $part1 (sort(keys(%{$HoHoA{$set1}}))) { #note that the earlier shift has already taken off #the part we don't want to match against foreach my $set2 (@sets) { foreach my $part2 (sort(keys(%{$HoHoA{$set2}}))) { print "$part1 - $part2\n"; } } } }
Note that this is still pretty damn inefficient because it sorts the sets of keys to match with every time it goes through the loop, but then again, this *does* sound like a school assignment, so that part is up to the OP. What looks to me to be the most efficient solution is to first make a pass through the entire HoH(the fact that the keys point at arrays in this specific case is entirely irrelevant) and make a sorted array for each set of keys and assign these to a HoA instead. Then, once the sorting is done you could simply foreach through the HoA and do the matching you wanted. If this is indeed, as i expect, a school assignment the latter solution would be, especially when the data gets bigger, a lot more efficient than the one I gave you and thus get you a better grade ;-)


Remember rule one...

In reply to Re: Getting Pairs of 2nd-ary Keys in HoHoA by Forsaken
in thread 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.