bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] getline difference from gawk versions >=4.0.0


From: Brian Kernighan
Subject: Re: [bug-gawk] getline difference from gawk versions >=4.0.0
Date: Mon, 2 Apr 2012 10:56:39 -0400 (EDT)
User-agent: Alpine 2.02 (LRH 1266 2009-07-14)

Interesting.  It's not clear what the "right" answer is, since arguably
if there was no input value, nothing should be stored in the array and
thus the increment should not happen.  (This is a weak argument, of
course.)  In my case, it's definitely an artifact of implementation,
and it could easily be changed.

Getline should have been a function.

Brian

On Mon, 2 Apr 2012, address@hidden wrote:

Greetings. Re this:

Date: Sun, 01 Apr 2012 11:49:33 +0100
From: Duncan Moore <address@hidden>
To: "address@hidden" <address@hidden>
Subject: [bug-gawk] getline difference from gawk versions >=4.0.0

Hi

b.awk:

BEGIN {
   system("echo 1 > f")
   while ((getline a[++c] < "f") > 0) {}
   print c
}

gawk -f b.awk

Prior to gawk 4.0.0 this outputs:

1

For 4.0.0 and 4.0.1 it outputs:

2

Regards
Duncan Moore

This is an interesting test case. I get different answers with different
versions of awk. Brian Kernighan's awk prints 1, mawk prints 2.

It is clearly an artifact of the implementation, although I think that
in this case 2 is the correct answer; the expression creating the "lvalue"
to be assigned for getline should be completely evaluated before getline
is invoked, making getline act more like a function call.

It is probably worth documenting this as Yet Another Dark Corner in
the language.

Thanks!

Arnold




reply via email to

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