[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] sorting algorithms



On Thu, 9 Nov 2000, Scott R. Godin wrote:
> $master_maps_list{$gametype}{lc($title)} = [$filename, $title, $size,
> $review, $rating];
>
> how do I sort this data by $size and then by $filename/$title for the subset
> of one of the five $gametype's ?

Try something like:

@sordid = sort { $a->[2] <=> $b->[2] ||
		 $a->[0] cmp $a->[0] }
	@{$master_maps_list{$gametype}{lc($title)}};

In other words, do a numerical (<=>) comparison of the 3rd array
element, and sub sort alphabetically on the first element, assuming I've
typed everything in right.

You will probably want to read under the sort section in the perlfunc
manual page; O'Reilly's Perl Cookbook also has some examples on doing
sorting, and the O'Reilly Programming Perl a section on where in the
world the perl sorting sytax came from (lisp, if memory serves).

-- 
Jeremy A. Mates                       (206) 221-4714   Fax: 685-7301
Senior Systems Administrator          K 353B, Health Sciences Center
http://www.mbt.washington.edu/        Mail Box 357730
University of Washington              Seattle, WA  98195


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org