SPUG: Sorting hash question

Marc M. Adkins Marc.M.Adkins at Doorways.org
Tue Apr 30 17:44:14 CDT 2002


You might try the Tie-SortHash module on CPAN:

	http://search.cpan.org/doc/CTWETEN/Tie-SortHash-1.01/SortHash.pm

It is designed to return keys in sorted order.  Don't know how much more
efficient it will be than your default solution.

mma

> 	I'm getting at the Children of Item using:
> 		for $SubItem (values %{$$Item{Children}})
>
> 	which gives me an unsorted list of items.  I would like to
> have it sorted
> in the order of the keys of the %{$Item{Children}}.  I found lots
> of info on
> how to step through the keys of a hash sorted by value, but not
> anything on
> stepping through the values of a has sorted by key.  Is this
> easily doable,
> or should I do something like:
>
> 	for $SubItem (sort {$a<=>$b} keys %{$$Item{Children}})
> 	{
> 		$SubItem = $$Item{Children}{$SubItem};
> 		...
> 	}
>
> 	I would be greatfull for any suggestion! :)
> Thanks,
> Peter Darley


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org




More information about the spug-list mailing list