⭐ in reply to How do I write my own sorting routine?
Now to sort, we just compare the array elements as keys into the hash:my %hash = ( "very slow" => 1, "slow" => 2, "slowish" => 3, "medium" => 4, "acceptable" => 5, "fast" => 6, "very fast" => 7, );
Hence:my @sorted = sort { $hash{$a} <=> $hash{$b} } @array;
would sort into:my @array = ("slow", "very fast", "fast", "very slow", "acceptable");
very slow, slow, acceptable, fast, very fast
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Answer: How do I write my own sorting routine?
by Roger (Parson) on Dec 22, 2003 at 12:44 UTC |