develooper Front page | perl.perl6.language.objects | Postings from August 2000

Re: RFC 124 (v1) Sort order for any hash

From:
Damian Conway
Date:
August 18, 2000 01:51
Subject:
Re: RFC 124 (v1) Sort order for any hash
Message ID:
200008180711.RAA76295@arnie.csse.monash.edu.au
   > How about
   > 	
   > 	%students : ( sort = $$students{^1}{GPA} <=> $$students{^0}{GPA} });

Weeeeeeird! :-)

Since you've strayed so close, why not go all the way and make it an attribute:

	my %students : sorted( $ME{^1}{GPA} <=> $ME{^0}{GPA} );

Where the C<sorted> attribute takes a block/sub ref/h.o.f. that expects
to compare two keys, which would be passed as arguments. Note too the
(now generalized) use of the proposed $ME variable.

Voila! A syntax entirely consistent with other existing and proposed
Perl usages.


Damian



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About