in reply to Move matched to top, bottom
Can this sort usage be relied upon?
No, not entirely. You're asking that no other entries change places with respect to each other, except on the criteria of matching some regex (in your example, /Endbit/i). That requires a stable sort, which perl does not entirely guarantee in all circumstances. Look at the sort documentation and search for the word 'stable' to see what this means, and how you can get a stable sort at all times.
Am I missing obvious alternative(s) ?
I think the most obvious solution is just to seperate out all the entries into two arrays, and then merge them together afterwards. Something like this:
That's not to say this is the most efficient algorithm - but you asked for obvious ;-)my (@match, @notmatch); for (@rawentries) { if (/Endbit/i) { push @match, $_; } else { push @notmatch, $_; } } my @newlist = (@notmatch, @match); # the ones that match float to the +bottom
|
|---|