test/cases/dsl-sorts/sortaf-func-lit/mlr
raw| 1 | # Sort descending numeric on the index field |
| 2 | begin { |
| 3 | @records = []; # Define as an array, else auto-create will make a map |
| 4 | } |
| 5 | @records[NR] = $*; # Accumulate |
| 6 | end { |
| 7 | @records = sort(@records, func (a, b) { |
| 8 | return b.index <=> a.index; |
| 9 | }); |
| 10 | for (record in @records) { |
| 11 | emit record; |
| 12 | } |
| 13 | } |