SPUG: Sorting hash question

Damian Conway damian at conway.org
Tue Apr 30 16:48:17 CDT 2002


Peter Darley wrote:

>         The variable $Item is actually a reference in a scalar, rather than a hash,
> so I need to re-reference it to $$Item{Children} before dereferencing it to
> %{$$Item{Children}}, if that makes any sense.  If I don't need to do this, I
> would be ecstatic, but it has been the only way I could figure out to do it.
> Any suggestions?

You'll still need to dereference, but it's better written as:

	%{$Item->{Children}}

Which would make my suggestion:

	for $SubItem (@{$Item->{Children}}{sort {$a<=>$b} keys %{$Item->{Children}}}) {
	    ...
	}

Damian

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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