in the subroutine we just have to compare two variables $a and $b. you dont have to define them. just compare then and return the value as your wish. then call it via sort.
−1, 0, or 1 as needed to sort them numerically.
- sub by_number { $b <=> $a };
-
@new = sort by_number @num;
-
print "@new";
90210 2001 1000 666 17 04 4 3.14159 1.50 1.5 -10
there’s a corre-sponding three-way string-comparison operator: cmp.