in reply to Move matched to top, bottom

The following may appeal:

use strict; use warnings; my @rawentries = ( "1topEndbit", "2ndbit", "endBit3", "4thbit", "5thbit", "6OtherEndbit", "7Bitsecondfromend", "8Bitoneoffend", "9Anyoldbit", ); my @sorted; my @last; /Endbit/i ? push @last, $_ : push @sorted, $_ for @rawentries; push @sorted, @last; print join "\n", @sorted;

Prints:

2ndbit 4thbit 5thbit 7Bitsecondfromend 8Bitoneoffend 9Anyoldbit 1topEndbit endBit3 6OtherEndbit

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Move matched to top, bottom
by quinkan (Monk) on May 03, 2006 at 00:39 UTC
    Thanks for that. Looks a good deal faster, too (which I guess is to be expected when a sort is involved, particularly if we start with initially-sorted or close-to-sorted data -- even with median partition selections).

    Oops ! I see 5.8 has changed sort to allow a change from the quicksort to mergesort, so median-of-three need not be the point.. (Thanks for the pointer, Tanktalus.)