Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Sorting a hahs of hashes

Reply
Thread Tools

Sorting a hahs of hashes

 
 
Me
Guest
Posts: n/a
 
      01-24-2005
I have a hash (of a hashes) that has data like this
table1->table_name
->table_size
table2->table_name
->table_size
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-24-2005
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
 
Reply With Quote
 
 
 
 
Tore Aursand
Guest
Posts: n/a
 
      01-24-2005
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:umper module.


--
Tore Aursand <(E-Mail Removed)>
"Be nice to nerds. Chances are you'll end up working for one." (Bill
Gates)
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      01-24-2005
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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
On Hashes - How the hashes printing works? Neela megha shyam Chivukula Ruby 4 05-28-2009 10:56 AM
How to make an array of hashes to a single array with all thevalues of these hashes ? kazaam Ruby 12 09-13-2007 01:30 PM
using hashes as keys in hashes Steven Arnold Ruby 3 11-23-2005 03:25 PM
Hash of hashes, of hashes, of arrays of hashes Tim O'Donovan Perl Misc 5 10-28-2005 05:59 AM
Hashes of Hashes via subs Ben Holness Perl 8 10-08-2003 06:57 AM



Advertisments