Sorting a hahs of hashes

Discussion in 'Perl Misc' 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 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.


    perldoc -q "sort a hash"

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jan 24, 2005
    #2
    1. Advertising

  3. Me

    Tore Aursand Guest

    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


    Please post the real code. If not, at least provide us with the output
    of the hash's structure as reported by the Data::Dumper module.


    --
    Tore Aursand <>
    "Be nice to nerds. Chances are you'll end up working for one." (Bill
    Gates)
     
    Tore Aursand, Jan 24, 2005
    #3
  4. 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 your 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
    #4
    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. Ben Holness

    Hashes of Hashes via subs

    Ben Holness, Oct 5, 2003, in forum: Perl
    Replies:
    8
    Views:
    568
    Ben Holness
    Oct 8, 2003
  2. Steven Arnold

    using hashes as keys in hashes

    Steven Arnold, Nov 23, 2005, in forum: Ruby
    Replies:
    3
    Views:
    163
    Mauricio Fernández
    Nov 23, 2005
  3. kazaam
    Replies:
    12
    Views:
    278
    Matthias Wächter
    Sep 13, 2007
  4. Neela megha shyam Chivukula

    On Hashes - How the hashes printing works?

    Neela megha shyam Chivukula, May 27, 2009, in forum: Ruby
    Replies:
    4
    Views:
    244
    Markus Schirp
    May 28, 2009
  5. Tim O'Donovan

    Hash of hashes, of hashes, of arrays of hashes

    Tim O'Donovan, Oct 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    216
Loading...

Share This Page