bug > gawk does not accept a third argument for the comparison function.
gawk version : GNU Awk 3.1.6
windows : 64bits
error : fatal: 3 is invalid as number of arguments for asort
Bug : The alternative way (PROCINFO["sorted_in"] = "mysortfunction") is not taken into account.
see file attached.
# objective : sort in a numerical order by the first colum (out of 2 colums)
BEGIN {
OFS="\t"
PROCINFO["sorted_in"] = "cmp_val"
delete s
delete d
for (i=1;i<12;i++)
s[i] = (i-8)**4 "\t" i
# n=asort(s,d, "cmp_val") # <= fatal: 3 is invalid as number of arguments for asort
n=asort(s,d )
print "==== orig ==="
for (i=1;i<12;i++)
print s[i]
print "==== asort ==="
for (i=1;i<12;i++)
print d[i]
print "==== PROCINFO=== "
for(j in s)
print s[j]
}
function cmp_val(i1, v1, i2, v2)
{
split(v1,a1,"\t")
split(v2,a2,"\t")
x1 = a1[1]+0
x2 = a2[1]+0
return (x1 - x2)
}