Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^2: Sort over remaining part of array

by Anonymous Monk
on Nov 12, 2013 at 10:39 UTC ( #1062173=note: print w/replies, xml ) Need Help??

in reply to Re: Sort over remaining part of array
in thread Sort over remaining part of array

I'd sort first, then remove duplicates

I've still no idea what resample means

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd pp /; my @AoA = ( [ 0.5, "b1", "c0" ], [ 0.4, "b1", "c1" ], [ 0.7, "b2", "c2" ], [ 0.3, "b3", "c3" ], [ 0.6, "b3", "c4" ], ); dd\@AoA; @AoA = sort { $$b[0] <=> $$a[0] } @AoA; dd\@AoA; { my %seen; @AoA = grep{!$seen{$$_[1]}++}@AoA; } dd\@AoA; __END__ [ [0.5, "b1", "c0"], [0.4, "b1", "c1"], [0.7, "b2", "c2"], [0.3, "b3", "c3"], [0.6, "b3", "c4"], ] [ [0.7, "b2", "c2"], [0.6, "b3", "c4"], [0.5, "b1", "c0"], [0.4, "b1", "c1"], [0.3, "b3", "c3"], ] [[0.7, "b2", "c2"], [0.6, "b3", "c4"], [0.5, "b1", "c0"]]

Also worth considering are Sort::Key - the fastest way to sort anything in Perl

and Sort::Key::External allows to sort huge lists that do not fit in the available memory.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1062173]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2021-03-02 18:00 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (57 votes). Check out past polls.