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: arnold
Subject: Re: [bug-gawk] How awk keys are ordered?
Date: Tue, 20 Dec 2016 21:48:20 -0700
User-agent: Heirloom mailx 12.4 7/29/08

Quite right. Gawk has additional optimizations for arrays
indexed only by integers.  Running the program with another
awk will defintiely give different results.

david kerns <address@hidden> wrote:

> 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]