WeBWorKdocs

sq_webwork:


Home
Current UR
courses
Visitor
page
Intro to
WeBWorK
WeBWorK 2
Twiki
WW
Community
Grant Support
& awards
Discussion
group
Problem
library
Write/modify
problems
Create &
manage course
Tutorial on
running a course
HowTos
FAQ
WeBWorK2
FAQ
Software
Download
How to
Install WW server
Feedback
Site Map
Change
preferences
Change
password





Prev | Next | manpages

Description

General sorting macro

Syntax

PGsort( &sort_subroutine, @list);

Params

&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

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

Examples

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

Notes

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

lex_sort
num_sort
uniq

Macro Definition File

PGbasicmacros.pl

<| Post or View Comments |>


Prev | Next | manpages

Last update: Wednesday, January 10, 2007 at 10:21:43 PM.
This site maintained using Manila and Frontier software.