Read it from right to left.

@AoA (which from its name we can assume is an array of arrayrefs) is the input to grep. grep filters it, and spits out a list that is the same size or smaller than @AoA and that list gets put into @r.

The bit inside braces is how grep filters. Each value from @AoA in turn is assigned to $_ and then the contents of the braces are executed. If the result is true, the array element is spat back out, otherwise it isn't - it gets filtered out.

join $;, sort @$_ first dereferences $_, which is assumed to be an array reference, giving a list. That list is sorted. It is then glued together to make a string, using $; as the separator. $; is an obsolete hangover from perl4, whose default value is an unprintable ASCII character, see perlvar for details.

This string is then used as a key in the %uniq hash to look up a value or, if the key doesn't exist, create it. ++ is a pre-increment, meaning that the value we just got from the hash is incremented before being used. Finally the == compares that incremented value to 1.

The overall result is that @r contains only the unique elements of @AoA, where two elements are defined to be the same if they have the same number of elements with the same values but in any order.

The code is buggy, as it may fail if elements contain $;. It would be better to use something like Text::CSV_XS instead of the naïve join.


In reply to Re: code explanation by DrHyde
in thread code explanation by ramdat

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.