Thread: gawk asort normal comparison confusion
i'm new gawk. read asort function sorts data element values; when no sort function specified, in default order (which took numerical sort or lexicographic sort respectively). not understand why below output...
output:
, independent on single letter choose xxx, long letter distinct other array indices a, g, , m.code:index: 4 - value: 4 index: 1 - value: 1 index: 2 - value: 2 index: 3 - value: 3
command line entered:
i didn't find reference default comparison criterion on gawk's man page, might have overlooked it. googling produces examples in lexicographic ordering works expected, i'm bit @ loss.code:$ gawk 'begin{ >var["a"] = 1 >var["g"] = 2 >var["m"] = 3 >var["xxx"] = 4 >asort(var, test) >for (i in test) >print "index: " i, " - value:", test[i] }'
note:
- problem similar using asorti
- i'm working under ubuntu 10.04.
i don't use gawk much, according documentation, indices of array not used, set of values.
next problem 'for (i in test)' seemingly ignores indices: returns values in random order.
produces sorted output, @ least:
code:gawk 'begin{ var[1] = "1" var[2] = "4" var[3] = "3" var[4] = "2" asort(var, test) (i=1; i<=length(test); i++) print "index: " i, " - value:", test[i] }'
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] gawk asort normal comparison confusion
Ubuntu

Comments
Post a Comment