use sort 'stable';
@new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
- # force use of quicksort (not portable outside Perl 5.8)
- use sort '_quicksort'; # note discouraging _
+ # force use of mergesort (not portable outside Perl 5.8)
+ use sort '_mergesort'; # note discouraging _
@new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
- # similar to the previous example, but demand stability as well
- use sort qw( _mergesort stable );
+ # Similar to the previous example, but demand stability as well
+ # Because of the way quicksort is "stabilized", this combination
+ # is not threadsafe
+ use sort qw( _quicksort stable );
@new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
If you're using strict, you I<must not> declare $a