SPUG: Sorting hash question
Peter Darley
pdarley at kinesis-cem.com
Tue Apr 30 13:25:06 CDT 2002
Friends,
I currently have a hash that looks like
$Item{Children}{[child #]}{other stuff}
A couple of examples would be:
$Item{Children}{1}{name}
$Item{Children}{1}{content}
$Item{Children}{2}{name}
$Item{Children}{2}{content}
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