It looks to me as if you are not doing a sort, but rather grouping only. The order is the order returned by the keys statement, which is undefined (disclaimer: it is snowing here; I had to battle Jack Frost twice, and the snowplow once this morning, so I may be as hazy as the sky outside of my window).
To sort, you could nested loops on sort keys... (as noted by SuicideJunkie above) at each level of the data structure. This might be the simplest option.
You could also extract all levels of the structure's keys ([[reg1,ctry1,city1][reg2,ctry2,city2]...]), sort these, and then extract the data from the hash given these sorted values.
You could also join the keys into a single string for each entry (["reg1:ctry1:city1","reg2:ctry2:city2"...]), sort these, and extract the data from the hash using these sorted values (be careful of what you choose to use as the delimiter here).
On the last two, a Schwarzian Transform might (or might not) buy you some performance or understanding for your maintenance programmers, but you would need to benchmark the options to be sure what works best in your situation.
This all depends on your data structures (see kennethk above), how you build them, and how large your data set is.
Update: Added some clarification and credit. I was way too slow posting my response ;-)
--MidLifeXis
In reply to Re: Sort a Hash 3 Levels Deep
by MidLifeXis
in thread Sort a Hash 3 Levels Deep
by Dru
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |