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

Re: [MacPerl] sorting multidimensional hashes



On 19 Apr 2000 02:01:49 PDT, Nicholas G. Thornton wrote:

>which I can easily figure out how to parse into an array of hashes (i.e. @db ->
>$db[unique quote number]{name, category...} = data) I'm wondering how I could go
>about sorting this via the key (as 'name' or 'category'); or if there's a better
>way to get the same result?

@db contains hash references.

     @db1 = sort { $a->{category} cmp $b->{category} } @db;

or, by sorting the indices:

     @db2 = @db[ sort { $db[$a]{name} cmp $db[$b]{name} } 0 .. $#db ];


Since both resulting arrays store the same hash references, the records
themselves are kept in memory only once.

-- 
	Bart.

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