Okay, so I've been trying, for quite a while, to sort a AoH(Array of Hash references) or AoA(Array of array references) by the frequency of duplicates. But duplicates of only 3 of 6 elements in the array or values of the hash.

If that doesn't make sense, I'm trying to use the sort found under the "Simple Aggregate" heading in the Tutorial: The Uniqueness of hashes. But for a data structure.

Here is what I've (pitifully) gotten so far:

my @array1 = (1 .. 20); my @array2 = (10 .. 30); my @array3 = (19 .. 40); push @all_arrays, \@array1, \@array2, \@array3; ##This is like what wi +ll be passed in my actual code my %unique_descriptive = do { local %_; for (@{$all_arrays[0]}, @{$all_arrays[1]}, @{$all_arrays[2]}) { $_{$_}->{count}++ ; push @{$_{$_}->{values}},$_; } %_; };

I need help with this step. It works as I would like it to (that is, gives number of times each number has been seen), but I can only apply this when I know @all_arrays is made up of exactly 3 array references. Also, I am doubting that I actually understand what is going on with the de-referencing?, so any help on that would be great.

I would like some help in doing what the above code does for an array that I don't know the size of (so I can't just list the de-referenced versions in the for loop). Sort of like the equivalent of:  @{@all_arrays}, which doesn't work.

I've tried looking at Sort::ArrayofArrays, but couldn't implement it. The tutorial says it's easy to apply to 2d data structures but... I failed.

Thanks a lot! Let me know if I need to be more clear.

Next steps (not being asked, but any tips are welcome): Actually sort by the frequency then make it sort by only the elements/values I want.


In reply to How to (get started on) sort AoA or AoH by frequency by jonc

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.