develooper Front page | perl.perl5.porters | Postings from August 2016

Re: [perl #39358] sort with custom subname and prototype ($$)segfaults intermittently

John P. Linderman
August 10, 2016 21:03
Re: [perl #39358] sort with custom subname and prototype ($$)segfaults intermittently
Message ID:
#!/usr/bin/perl -w
@scores = (
@match_indices = (0,1,2,3);
sub sort_by_index($$) {
    my($A,$B) = @_;
    return $scores[$match_indices[$A]] cmp
@match_indices = sort sort_by_index @match_indices;

This could be "fixed" at the expense of allocating *two* extra arrays
instead of just one (which is already more than quicksort, which sorts "in
place"). But I wonder why people think that the contents of any array in
the process of being sorted can participate in any meaningful way in a
comparison. Must all sort implementations guarantee that the intermediate
contents of the array to be sorted are some permutation of the original
array? I don't like the idea of penalizing *all* users for the dubious
intent of *some* users. Segfaults are evil, of course. A better solution
would be to somehow mark an array as "off limits" while a sort is in
progress, but that's way beyond my pay grade. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About