#!./perl
-# $RCSfile: sort.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:24 $
-
-print "1..21\n";
+print "1..27\n";
sub backwards { $a lt $b ? 1 : $a gt $b ? -1 : 0 }
my @result = sort 'one', 'two';
CODE
print $@ ? "not ok 21\n# $@" : "ok 21\n";
+
+{
+ my $sortsub = \&backwards;
+ my $sortglob = *backwards;
+ my $sortname = 'backwards';
+ @b = sort $sortsub 4,1,3,2;
+ print ("@b" eq '4 3 2 1' ? "ok 22\n" : "not ok 22 |@b|\n");
+ @b = sort $sortglob 4,1,3,2;
+ print ("@b" eq '4 3 2 1' ? "ok 23\n" : "not ok 23 |@b|\n");
+ @b = sort $sortname 4,1,3,2;
+ print ("@b" eq '4 3 2 1' ? "ok 24\n" : "not ok 24 |@b|\n");
+}
+
+{
+ local $sortsub = \&backwards;
+ local $sortglob = *backwards;
+ local $sortname = 'backwards';
+ @b = sort $sortsub 4,1,3,2;
+ print ("@b" eq '4 3 2 1' ? "ok 25\n" : "not ok 22 |@b|\n");
+ @b = sort $sortglob 4,1,3,2;
+ print ("@b" eq '4 3 2 1' ? "ok 26\n" : "not ok 23 |@b|\n");
+ @b = sort $sortname 4,1,3,2;
+ print ("@b" eq '4 3 2 1' ? "ok 27\n" : "not ok 24 |@b|\n");
+}
+
test "@sorted", '22 11 5 2 1'; # 189
# Scalar
test $$deref, 123; # 190
- # Glob
- @sorted = sort $deref 11, 2, 5, 1, 22;
+ # Code
+ @sorted = sort $srt 11, 2, 5, 1, 22;
test "@sorted", '22 11 5 2 1'; # 191
# Array
test "@$deref", '11 12 13'; # 192