Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

how to sort

by Anonymous Monk
on Sep 13, 2013 at 13:03 UTC ( #1053920=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i have three arrays:

@arr_thumbnail

@arr_url

@arr_score

they are in sequential order, eg, The thumbnail $arr_thumbnail[5] has a target of $arr_url[5] with a score of $arr_score[5].

I want to sort by "score", while the corresponding thumbnail and url will still be linked to the score. I know it would be very easy if i'm using a sql table, but it seems too overkill , are there any way to sort it without using sql?

Replies are listed 'Best First'.
Re: how to sort
by Corion (Pope) on Sep 13, 2013 at 13:06 UTC

    Sort the indices, not the arrays themselves:

    my @indices= 0..$#arr_score; @indices= sort { $arr_score[ $a ] <=> $arr_score[ $b ] } @indices; for my $i (@indices) { print "$arr_thumbnail[ $i ] - $arr_url[ $i ] - $arr_score[ $i ]\n" +; };

    Alternatively, restructure your data into hashes, and sort that array.

Re: how to sort
by glenn (Scribe) on Sep 13, 2013 at 14:01 UTC
Re: how to sort
by Anonymous Monk on Sep 13, 2013 at 16:31 UTC
    Make one array containing hashrefs with three keys: thumbnail, url, and score. Sort this array. Keeps them all together.
Re: how to sort
by Marshall (Monsignor) on Sep 13, 2013 at 13:40 UTC
    I would suggest:
    http://search.cpan.org/~adamk/List-MoreUtils-0.33/lib/List/MoreUtils.pm

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2016-09-27 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (504 votes). Check out past polls.