in reply to Sorting Arrays

You can use a modified Schwartizan transformation for that:
my $i = 0; my @sorted_indicies = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $_, $i++ ] } @array; # OR my @sorted_indicies = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $array[$_], $_ ] } (0..$#array);
(The first requires the extra varaible, while the second requires you use the array variable twice.)

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
"I can see my house from here!"
It's not what you know, but knowing how to find it if you don't know that's important

Replies are listed 'Best First'.
Re: Re: Sorting Arrays
by merlyn (Sage) on Jan 08, 2002 at 21:59 UTC
    If you'll grant me an audience knowing that I know a bit about the Schwartzian Transform... {grin}

    The ST makes sense only when the orderingfunction on each element to be sorted is expensive to compute, and should therefore be cached to prevent multiple calls (so the list has to be long enough as well). Since "array lookup" is a cheap (nearly free) orderingfunction, the ST is far too much overkill on this choice.

    -- Randal L. Schwartz, Perl hacker