Forum archive 2000-2006

Barbra Bannon - Perl Sort function

Barbra Bannon - Perl Sort function

by Arnold Pizer -
Number of replies: 0
inactiveTopicPerl Sort function topic started 10/26/2001; 12:36:59 PM
last post 10/26/2001; 12:55:57 PM
userBarbra Bannon - Perl Sort function  blueArrow
10/26/2001; 12:36:59 PM (reads: 3457, responses: 1)
I'm trying to sort a simple array using the PERL sort function.

@a = ($h,$k,$l);

@a1 = sort {$a <=> $b} @a;

The error webworks is giving me is the following:

sort trapped by operation mask at (eval 50) line 72.

Can you help me? -Barbra Bannon

<| Post or View Comments |>

userMichael Gage - Re: Perl Sort function  blueArrow
10/26/2001; 12:55:57 PM (reads: 3699, responses: 0)
This is in, but hasn't received documentation yet -- you have to look at the source code.


sub lex_sort {
PGsort sub {$_[0] cmp $_[1]}, @_;
sub num_sort {
PGsort sub {$_[0] <=> $_[1]}, @_;

Use it like this:

@out_array = lex_sort(@array); will sort the array lexigraphically

@out_array = num_sort(@array); will sort it numerically.

PGsort is defined in if you want to do something more esoteric. sort can be used to hang the execution of a problem, so we have made it available only through the PGsort alias. At the moment PGsort doesn't actually do much to protect against abuse, but the hook is there to install a time out or some other protection if we ever discover that we need it.

-- Mike

<| Post or View Comments |>