in reply to Keeping "keys" in order when passed to an Array
Ordinarily, sort would be used:
Your question seems odd to me, because if this is representative code, then @sorted_scores and @sorted_line_nums will have corresponding values. There are no situations I've come across that need the internal hash "order" to be preserved. Since the internal hash order is data dependent, version dependent, (and possibly platform dependent,) I've always used sort when I need order.my @sorted_scores = sort keys %hashFinal; my @sorted_line_nums = map { $Reversevalues{$_} } @sorted_scores;
I can imagine some situations where you want the insert order, yet still need to use the associative lookup capability of a hash. In that case, gaal's suggestion of Tie::IxHash seems right on. Any other order implies an ability to discriminate a correctly ordered list and an incorrectly ordered list, and again sort is recommended.
Perhaps you've just overlooked that sort can take a user supplied sort subroutine?
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
|---|