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

Re: [MacPerl] sorting arrays



On Thu, 17 Jun 1999 01:16:38 -0400, Ronald J Kimball wrote:

>Well, someone suggested using hashes to solve this problem of sorting a
>file, and I'd like to see just what they had in mind!

Yes, we know, you wrote that 3 times already. So, in order to prevent
you to reapeat that another 3 times, I'll venture a guess. ;-)

	@sorted = sort { $hash{$a} cmp $hash{$b} } @array;

where the hash serves as a value cache, that contains the stuff you'd
calculate fro the S.T. It should work nicely when comparing for example
file dates (using "<=>" instead of "cmp").

	Bart.

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