http://qs321.pair.com?node_id=268570


in reply to Sorting hash keys according to different criteria

Short answer is no, long answer is maybe. No, there is no way to "order the hash". As it is written, so it shall be done. But seriously, the docs aren't lying to you, Perl stores it hashes the way it wants. No guarantee of ordering when you retrieve them.

Now I say maybe because you may feel free to write your own sorting algorithm to sort then on the fly when you want to print them out. Some clever use of the Time::localtime module to convert the month name into a number. However, since you are dealing with 12 pieces of data, that seems like overkill. Honestly, an array with the Names of the months as elements would work perfectly for your needs.

  • Comment on Re: Sorting hash keys according to different criteria