in reply to Remembering original order of an array

I have just figured out a short solution using map:
my $i=0; my @sorted_indexes=map {$_->[1]}sort{ $a->[0] <=> $b->[0] }map{[$_,$i+ ++]}@array; foreach my $d(@sorted_indexes){ print $d."\t".$array[$d]."\n"; }
Thanks to all who were even beginning to consider this...:-)

Replies are listed 'Best First'.
Re^2: Remembering original order of an array
by ikegami (Patriarch) on Sep 04, 2007 at 19:27 UTC

    That produces a different output than your original post, but if that's what you want, it can be simplified to:

    my @sorted_indexes = sort { $array[$a] cmp $array[$b] } 0..$#array;

    Note that cmp (not <=>) should be used here since you are comparing strings (not numbers).