Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2020-10-31 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (287 votes). Check out past polls.

    Notices?