
fox
Novice
Jun 26, 2003, 9:31 PM
Post #1 of 4
(855 views)
|
Hi, How can I sort a hash that has keys like this $res{"1 "."123456789"." 1"}=$tmp; $res{"1 "."124456789"." 2"}=$tmp; $res{"2 "."125456789"." 3"}=$tmp; $res{"2 "."126456789"." 4"}=$tmp; $res{"3 "."127456789"." 5"}=$tmp; $res{"3 "."128456789"." 6"}=$tmp; I need to sort %res by the middle section there. I'm using the simple foreach $key (sort keys %res){ } but it cant sort by the middle section properly because of the beginning and trailing difference. I was hoping I could learn some advanced sorting and maybe map would come into use because i never learned to use the map function. Still today after 4 years It's not clear to me, Oh, and the first part of the hash is for an order, so it has to keep it in mind in the sorting process. The keys that begin with 1 are to be displayed at the top of the results, and then the results marked 2nd and 3rd. It works great for everything in my search engine, except it can handle sorting by the timestamp. And the trailing number is just something different to keep the key unique. Does this make sense? Thanks, Tony
|