sorting a hash by key value

Discussion in 'Perl' started by Me, Jan 24, 2005.

  1. Me

    Me Guest

    I have a hash (of a hashes) that has data like this
    table1->table_name
    ->table_size
    table2->table_name
    ->table_size
    Me, Jan 24, 2005
    #1
    1. Advertising

  2. Me wrote:
    [...]
    > I need to sort the hash by table_size (numeric). How can I do this.


    You don't. Hashes by their very nature don't have an order or sequence.
    Therefore the term "sorting a hash" is about as meaningful as trying to sort
    the lenght() function. You have to use a different data structure.

    Having said that you Question is also Asked Frequently, please see
    "perldoc -q sort" for several suggestion about what to do instead.

    jue
    Jürgen Exner, Jan 24, 2005
    #2
    1. Advertising

  3. Do you mean to say you have an array of hash references? that they
    themselves have hash references?


    Me wrote:
    > I have a hash (of a hashes) that has data like this
    > table1->table_name
    > ->table_size
    > table2->table_name
    > ->table_size
    > .
    > .
    > .
    > table_n->table_name
    > ->table_size
    >
    >
    > I need to sort the hash by table_size (numeric). How can I do this.
    Michael Beattie, Jan 26, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vikas
    Replies:
    3
    Views:
    508
    CBFalconer
    Aug 16, 2007
  2. rp
    Replies:
    1
    Views:
    499
    red floyd
    Nov 10, 2011
  3. Une bévue
    Replies:
    5
    Views:
    141
    Une bévue
    Aug 10, 2006
  4. Antonio Quinonez
    Replies:
    2
    Views:
    156
    Antonio Quinonez
    Aug 14, 2003
  5. Replies:
    9
    Views:
    127
    Martien verbruggen
    May 17, 2007
Loading...

Share This Page