in reply to Advanced Sorting
which stops the code from examining every value twice, but simply evaluates a scalar. It benchmarks as slightly faster. Actually, for ultimate speed, move the field check before the sort subroutine is called:if ($field eq "name") { $a->{$field} cmp $b->{$field} } else { $a->{$field} <=> $b->{$field} }
etc...if ($field eq "name") { @sorted = sort @data; } else { @sorted = sort {$a <=> $b} @data; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Advanced Sorting
by Anonymous Monk on Oct 28, 2000 at 06:02 UTC | |
by little (Curate) on Oct 28, 2000 at 19:57 UTC | |
by merlyn (Sage) on Oct 28, 2000 at 20:06 UTC | |
by little (Curate) on Oct 28, 2000 at 21:49 UTC |