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