# patsplit() bug-report # # Latitude-E6410% uname --all # Linux Latitude-E6410 5.4.0-80-generic #90-Ubuntu SMP Fri Jul 9 22:49:44 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux # # Latitude-E6410% gawk --version # GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0) # # This file documents what I believe to be a bug in the # order of returned arrays. # # patsplit(string, array [, fieldpat [, seps ] ]) # # # Documented: # array contains the strings for each split using fieldpat # seps contains the separators used for each split using fieldpat # # As run on 1:5.0.1+dfsg-1 Ubuntu 20.04 # # The two returned arrays are reversed. # # gawk -f t.gawk # 6 a2:m6,a2:m6,b:m7.5-,e:7.9-,e:m7.5- # array[0]= : sep[0]= a # array[1]= 2 : sep[1]= :m6 # array[2]= , : sep[2]= a # array[3]= 2 : sep[3]= :m6 # array[4]= , : sep[4]= b:m7.5- # array[5]= , : sep[5]= e:7.9- # array[6]= , : sep[6]= e:m7.5- # function tst(str) { n = patsplit(str,px,/[,24]/,z); print n, str; for(i=0;i<=n;i++) print "#", "array[" i "]=",px[i], ": sep[" i "]=", z[i]; } BEGIN { Progression = "a2:m6,a2:m6,b:m7.5-,e:7.9-,e:m7.5-"; tst(Progression); }