test/cases/dsl-sorts/sortaf-func-lit-var-2/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 | f = cmp; |
| 11 | @records = sort(@records, f); |
| 12 | for (record in @records) { |
| 13 | emit record; |
| 14 | } |
| 15 | } |