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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |