bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] How awk keys are ordered?


From: david kerns
Subject: Re: [bug-gawk] How awk keys are ordered?
Date: Tue, 20 Dec 2016 15:36:35 -0700

I've been programing in awk since 1986. The Aho, Weinberger, Kernighan version of awk was always quite outspoken about "no user control" of the output order from a "for (i in a)" ... However, Gnu awk (aka gawk) "is not your father's awk" (I'm quite certain that quotation comes from someone who had people like me in mind) http://www.drdobbs.com/open-source/gnu-awk-this-is-not-your-fathers-awk/240158351

gawk has several methods to control "sorting arrays" ... read the docs or google the following:

asort()
asorti()
PROCINFO["sorted_in"]


On Tue, Dec 20, 2016 at 3:13 PM, Peng Yu <address@hidden> wrote:
Hi, The following shows that awk hash keys are ordered numerically
whether the actual keys are actually numbers or strings. Does anyone
know when this assumption of ordering is true? Thanks.

~$ cat main1.awk
# vim: set noexpandtab tabstop=2:

BEGIN {
    for(i=1;i<=26;i++) {
        array[i]=1
    }
    for(i in array) {
        print i
    }
    for(i=1;i<=26;i++) {
        array["" i] =1
    }
    for(i in array) {
        print i
    }
}
~$ awk -f ./main1.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26


--
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]