Forum archive 2000-2006

Michael Gage - PGsort

Michael Gage - PGsort

by Arnold Pizer -
Number of replies: 0
inactiveTopicPGsort topic started 11/16/2002; 7:30:55 AM
last post 11/16/2002; 7:30:55 AM
userMichael Gage - PGsort  blueArrow
11/16/2002; 7:30:55 AM (reads: 1652, responses: 0)


General sorting macro


PGsort( &sort_subroutine, @list);


&sort_subroutine is a subroutine of two variables which defines order. It's output must be -1, 0, 1 depending on whether the first variable is less than, equal to or greater than the second.
@list is the list to be sorted.


Returns list of elements in @list, ignoring duplicates. The order is unspecified.


join(" ",PGsort( sub {$_[0] <=> $_[1]} , (23,2,10,11,11,31); ); returns "2 10 11 11 23 31"


Using the perl sort directly in problems is not allowed for two reasons. The first is that the hardwired $a and $b variables used by sort can interfere with other values assigned to $a and $b. The second is that it is pretty easy to create closed loops with sort that hang the program. Currently nothing is done to prevent this, but later we may wish to modify num_sort and lex_sort to catch this problem.

See Also


Macro Definition File


<| Post or View Comments |>