SPUG: Another stupid question, hash sorting

Ben Reser ben at reser.org
Tue Jul 2 18:28:39 CDT 2002

On Tue, Jul 02, 2002 at 04:09:00PM -0700, Peter Darley wrote:
> 	I've got another stupid question that I'm hoping someone can answer for me.
> I want to sort a hash on two values, and have been unsuccessful in my search
> of the web for info on how to do it.
> 	Specifically I have a hash containing {Score} and {Name} values, and I want
> to primarily sort on score, and sort on name where the score is the same.  I
> can do this with a two step sort, but I figured that Perl was probably cool
> enough to provide a simple way of tackling this.

You can use the sort function of perl to achieve this.  Read:
perldoc -f sort

Pay particular attention to the block definition where you can define
your own criteria for determining sort positions...

At any rate this isn't a simple task that perl already has a built in to
handle.  You'll have to do some work on it yourself...

Ben Reser <ben at reser.org>

We tend to see all wars through the lens of the current conflict, and we
mine history for lessons convenient to the present purpose.
- Brian Hayes

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