http://www.perlmonks.org?node_id=459720


in reply to Getting the order of an array

To get the OP's desired output, one needs another loop such as the one below:
use strict; my @vector = qw( 27 32 46 5 102 76 ); my @order = sort{ $vector[ $a ] <=> $vector[ $b ] } 0 .. $#vector; my $i = 1; my @order_it; foreach (@order) { $order_it[$_] = $i++; } print join(' ',@order_it),"\n"; print "@vector[ @order ]\n";

Update: Updated to show the correct way to get the second part of the OP's answer. In answer to BrowserUk's comment, I took the original question to mean that both outputs are required but that the OP didn't realize they could not both be supported by a single array.