maybe less cryptic?

DB<154> @a0 = (-20,20,1,1,2,2,2,9,3,-4,-4,5,-20,20); => (-20, 20, 1, 1, 2, 2, 2, 9, 3, -4, -4, 5, -20, 20) DB<155> @a1 = ( 10,11,7,9,3,3,3,1,3, 4, 5,5, 1,30); => (10, 11, 7, 9, 3, 3, 3, 1, 3, 4, 5, 5, 1, 30) DB<156> map { push @{$group{$a0[$_]}},$a1[$_] } 0..$#a0 DB<157> sub highlander { my @sort = sort @{ shift() } ; return $sort[-1]>$sort[0] ? $sort[-1] : undef } DB<158> @high{keys %group } = map { highlander($_) } values %group => (undef, 5, undef, undef, 30, 9, 10, undef) DB<159> map { ($a0[$_],$a1[$_])=() if $a1[$_] != $high{ $a0[$_] } } +0..$#a0 DB<160> \@a0 => [ -20, undef, undef, 1, undef, undef, undef, undef, undef, undef, -4, undef, undef, 20, ] DB<161> \@a1 => [ 10, undef, undef, 9, undef, undef, undef, undef, undef, undef, 5, undef, undef, 30, ]

Cheers Rolf

( addicted to the Perl Programming Language)


In reply to Re^2: How do I remove the duplicates from the array? by LanX
in thread How do I remove the duplicates from the array? by PetreAdi

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.