http://qs321.pair.com?node_id=1062161


in reply to Sort over remaining part of array

I would like to sort it on the 1st column ($a are numerical, $b and $c are strings), take it line by line - if $b was seen before, resample $a and $b, then sort the remaining rows in array (including the current one) and analyze as before - until all $b's are unique.

Can you translate that into simple english please? And maybe post real sample data instead of "$a0"...?

Thanks

Replies are listed 'Best First'.
Re^2: Sort over remaining part of array
by Anonymous Monk on Nov 12, 2013 at 10:39 UTC

    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.