1 | sort() is a builtin PERL function with three modes: |
2 | @result = sort @array; # equivalent to sort { $a cmp $b} @array; |
3 | which sorts the variables in @array using stringwise comparisons, returning them in @result |
4 | @result = sort BLOCK @array; # where statement BLOCK enclosed in {} curly brackets returns -1, 0, 1 given values of $a, $b |
5 | @result = sort { $age{$a} <=> $age{$b} } @array; # sorts by age if entries in @arrays are keys to hash %age, which holds numeric age for each key |
6 | @result = sort SUBNAME @array; # uses subroutine (which can be specified as value of scalar variable) to perform sorting |
7 | sub backsort { $b <=> $a; } # Reverse order for integers |
8 | @result = sort backsort @array; # sorts in numerically decreasing order |