perl - Sort and array maintaining index value -
i stored values in array follows $score[$userindex] = :
score [100, 400, 900]
userindex (1 , 2 , 3 )
i need ascending numeric sort based on score while maintaining indexes, have significance, result should resemble:
score [100, 400, 900] userindex (2 , 1 , 3 )
2. after sort finish how can access previous index element at(after sort finish no longer need score indexes)? in sorted array need eg: $sorted[0] = 2, $sorted[1] = 1, $sorted[3] = 3
i found method of doing after extensive googling
while ($hashindex < $#score) { $matchhash{$hashindex} = $score[$hashindex]; $hashindex++; } foreach $score (sort { $matchhash{$a} <=> $matchhash{$b} } keys %matchhash) { #ds # printf "%-8s %s\n", $score, $matchhash{$score}; force (@sorted, $score); }
perl
No comments:
Post a Comment