Like I said yesterday, if you don't care about the order in which the values were added (if you are going to sort the output anyway, for example), you can store the $version as hash keys, rather than an array. (This is the rough equivalent of Python's sets, like what you showed us in the CB yesterday). Your structure can by using this statement instead of the push:

$hash->{$value}{$version}++; # The names you used yesterday
. And then you can iterate over it with:
for my $outer (keys %$hash) { my $subhash = $hash->{$outer}; for my $inner (sort { $a <=> $b } keys %$subhash) { # iterating over the sorted values } }
The values are stored unsorted, but you can just sort them at the last moment when going through them. You can use Data::Dump (or Data::Peek as pointed by Tux :) ). To see what the content of the $hash looks like.

Edit: try to avoid one-letter names, but never use $a outside of sort, as it has a special meaning for that case and some others (like some functions of List::Util)


In reply to Re: Understanding how sort uniq works by Eily
in thread Understanding how sort uniq works by ovedpo15

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.