Don’t want to sort the entries.
using this does not preserve the order as well
foreach my $val (keys %hash) {
...
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Hashes are unordered by default in Perl 5. You can use
tieandTie::IxHashto override this behavior. Be warned though, there is a performance hit and other considerations (like the fact that the order will not be preserved in copies).A better option may be to use an array or a hash of hashes:
As for performance, here are the results of a benchmark:
From this we can see that using Hash::Ordered is the way to go if you don’t need it to behave like a normal hash (ie a tied hash).
Here is the benchmark: