in reply to Optimizing a sort function (wrap-around alpha)

I'd write that as:
my @sorted = ((sort grep {$_ ge $top} @unsort), (sort grep {$_ lt $top} @unsort));
Or, if you really insist on a single sort:
my @sorted = map {substr $_, 1} sort map {sprintf "%s%s", (0, 1, 2)[$top cmp $_], $_} @unsorted;
Neither technique uses a sort block, and that usually means it's more efficient than a method using a sort block.

Replies are listed 'Best First'.
Re^2: Optimizing a sort function (wrap-around alpha)
by Anonymous Monk on Apr 15, 2005 at 11:33 UTC
    And yet another way:
    my %h; push @{$h{$_ cmp $top}}, $_ for @unsorted; my @sorted = (@{$h{0}}, sort(@{$h{1}}), sort(@{$h{-1}}));
    It's using a single pass bucket-sort as first step. Again note the absense of a sorting block.
Re^2: Optimizing a sort function (wrap-around alpha)
by bugbugbear (Initiate) on Apr 15, 2005 at 14:27 UTC
    For the latter solution, you must have meant [$_ cmp $top] instead of [$top cmp $_].