This is not only more compact, it's also a different, slower algorithm

To my eye it looks like the same algorithm as pg's solution, just rolled up into a single statement; what strikes you as different about it?

And running your benchmark script with a few additions indicates that it's actually faster than any of the alternatives you had included:

ewijaya              37879/s
ewijaya_longrand     38610/s
pg_longrand          96154/s
pg                  100000/s
aighearach          103093/s
aighearach_longrand 105263/s
scooterm            107527/s
scooterm_longrand   114943/s
simonm              117647/s
simonm_longrand     126582/s
simonm2             131579/s
simonm2_longrand    144928/s

I'm not sure why the results differ from those you showed; FWIW, I'm running 5.6.0 on darwin.

Here're the two subs I tested:

sub simonm { sort keys %{ { map { $_ => undef } map @$_, @_ } } } sub simonm2 { my ( %unique ); @unique{ map @$_, @_ } = (); sort keys %unique }

In reply to Re^4: More efficient way to get uniq list elements from list of lists by simonm
in thread More efficient way to get uniq list elements from list of lists by monkfan

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.