I've taken a quick look at global.conf.dist and I'm not sure of how to go about this.
Any pointers would be appreciated
Zak
$comparer = sub { ... }
# or
sub comparer { ... }
$L1 = PGsort ($comparer, @list1);
$L2 = PGsort ($comparer, @list2);
$comparer
). So, for example,
$compare = sub {$_[0] < $_[1]}; @list = (5,2,3,1,7,4,6); PGsort($compare,@list); # returns (1,2,3,4,5,6,7)
If you want to use a named function, then that requires using the use of ~~&
before the name when PGsort
is called. (Note that PG handles \
specially; because it is used in TeX, PG doubles all occurrences of \
, which makes it impossible to use it for its usual Perl meanings. So PG provides ~~
in place of \
. Pretty awkward, but it works.)
So you could do
sub compare {$_[0] < $_[1]}; @list = (5,2,3,1,7,4,6); PGsort(~~&compare,@list); # returns (1,2,3,4,5,6,7)in this case. Note that
$
and %
are not what you want in this case, since $
refers to a scalar variable (like the CODE reference in the first example above), while %
refers to a HASH (an associative array). You want &
, which is for CODE, so \&
would get you a code reference, but \
must be replaced by ~~
in PG, giving ~~&
here.
perl -v
on the command line on the server to tell).
$c = sub { ... }
$c = sub { ... };