in reply to Re: sort hashes....
in thread sort hashes....

Thanks for your help so far :) I already tried exactly the same code you suggest before, but the problem is I need to sort the hash accordingly (is this the right word, sorry i'm german :) ); i don't need a sorted list containing the strings. any ideas? sanchez

Replies are listed 'Best First'.
Re: Re: Re: sort hashes....
by sanchez (Initiate) on Aug 10, 2003 at 17:46 UTC
    hmmmm.....dammit can you even sort hashes...? lol thanks anyway :-)
      Hashes have no order. You can't "sort a hash." It's like a big canvas bag filled with all of the key-value pairs. Every time you look, somebody may have shaken the bag.

      Arrays have order. You can sort one array and collect the sorted version in another array. It's like a rope upon which all of the elements are tied at various points.

      When you say "sort a hash," you really mean, collect the keys or collect some part of the values, and generate a sorted array of those. That is, search through the bag and tie each item onto a rope, until all of the items in the bag are ALSO on the rope.

      Often, the first thing you do with this sorted array is to query the hash again, using the sorted array as an ordering guide. That is, following the knots on the rope to visit all of the items in the bag.

      I hope the metaphors help.

      --
      [ e d @ h a l l e y . c c ]