Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: sorting based on a list

by merlyn (Sage)
on May 09, 2001 at 18:36 UTC ( #79101=note: print w/replies, xml ) Need Help??


in reply to sorting based on a list

my @indicies = sort { $list[$a] cmp $list[$b] } 0..$#list; my @rearranged = @list2[@indicies];

-- Randal L. Schwartz, Perl hacker


update: Hold on. I solved the problem he stated. Not the problem he had. OK, nothing cannot be solved without a bit of indirection:
my @indicies = sort { $list[$a] cmp $list[$b] } 0..$#list; my @rearranged; @rearranged[@indicies] = sort @list2;
There. Make a sorted @list2 be disordered in the same way that @list is.

Also see my other solution.

Replies are listed 'Best First'.
Re: Re: sorting based on a list
by suaveant (Parson) on May 09, 2001 at 18:43 UTC
    Umm.. this returns zulu xray bravo alpha yankee charlie

    that's not ordered right...

    Update Yup, all better now
                    - Ant

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2020-01-27 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?