Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Sort over remaining part of array

by Anonymous Monk
on Nov 12, 2013 at 09:42 UTC ( [id://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"...?

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-26 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found