Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   sorting a hash by key value (http://www.velocityreviews.com/forums/t25449-sorting-a-hash-by-key-value.html)

Me 01-24-2005 08:19 AM

sorting a hash by key value
 
I have a hash (of a hashes) that has data like this
table1->table_name
->table_size
table2->table_name
->table_size

Jürgen Exner 01-24-2005 02:06 PM

Re: sorting a hash by key value
 
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




Michael Beattie 01-26-2005 03:00 AM

Re: sorting a hash by key value
 
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.



All times are GMT. The time now is 01:33 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.