in reply to sort index (head cold)
I don't think this is particularly efficient, but it does give the result I think you want. It might be easier to use map, but I haven't figured map out yet.#!/usr/bin/perl -w use strict; my (@newa, %hash, @sortedlist, @sortedindex); @newa = ('t', 'd', 'z', 'x'); @hash{@newa}=(0..$#newa); @sortedlist=sort @newa; @sortedindex=@hash{@sortedlist}; print "@sortedindex\n"; print "@newa[@sortedindex]\n";
is the output.1 0 3 2 d t x z
|
|---|