Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Sort over remaining part of array

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

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"...?


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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2021-02-25 17:34 GMT
Find Nodes?
    Voting Booth?

    No recent polls found