1*e6d6c189SCody Peter Mello#Date: Tue, 18 May 1999 12:48:07 -0500 (CDT) 2*e6d6c189SCody Peter Mello#From: Darrel Hankerson <hankedr@dms.auburn.edu> 3*e6d6c189SCody Peter Mello#To: arnold@gnu.org 4*e6d6c189SCody Peter Mello#Subject: [christopher.procter@bt.com: RE: Getline bug in Gawk 3.0.3] 5*e6d6c189SCody Peter Mello# 6*e6d6c189SCody Peter Mello#Here's a reply that came directly to me. --darrel 7*e6d6c189SCody Peter Mello# 8*e6d6c189SCody Peter Mello# 9*e6d6c189SCody Peter Mello#From: christopher.procter@bt.com 10*e6d6c189SCody Peter Mello#To: hankedr@dms.auburn.edu 11*e6d6c189SCody Peter Mello#Subject: RE: Getline bug in Gawk 3.0.3 12*e6d6c189SCody Peter Mello#Date: Tue, 18 May 1999 18:42:28 +0100 13*e6d6c189SCody Peter Mello# 14*e6d6c189SCody Peter Mello#Sorry that was me getting carried away and cut and pasting the wrong thing 15*e6d6c189SCody Peter Mello#into my email 16*e6d6c189SCody Peter Mello# 17*e6d6c189SCody Peter Mello#The real problem seems to be that : 18*e6d6c189SCody Peter Mello#BEGIN { 19*e6d6c189SCody Peter Mello#for (i=1;i<10;i++){ 20*e6d6c189SCody Peter Mello# while((getline < "hello.txt")>0){ 21*e6d6c189SCody Peter Mello# print $0 22*e6d6c189SCody Peter Mello# } 23*e6d6c189SCody Peter Mello# close("hello.txt") 24*e6d6c189SCody Peter Mello# } 25*e6d6c189SCody Peter Mello#} 26*e6d6c189SCody Peter Mello#works (printing the contents of hello.txt 9 times), where as:- 27*e6d6c189SCody Peter Mello# 28*e6d6c189SCody Peter Mello#END{ 29*e6d6c189SCody Peter Mello#for (i=1;i<10;i++){ 30*e6d6c189SCody Peter Mello# while((getline < "hello.txt")>0){ 31*e6d6c189SCody Peter Mello# print $0 32*e6d6c189SCody Peter Mello# } 33*e6d6c189SCody Peter Mello# close("hello.txt") 34*e6d6c189SCody Peter Mello# } 35*e6d6c189SCody Peter Mello#} 36*e6d6c189SCody Peter Mello# 37*e6d6c189SCody Peter Mello#doesn't, (it prints out hello.txt once followed by the iteration numbers 38*e6d6c189SCody Peter Mello#from 1 to 9). 39*e6d6c189SCody Peter Mello#The only difference is that one is in the BEGIN block and one in the END 40*e6d6c189SCody Peter Mello#block. 41*e6d6c189SCody Peter Mello# 42*e6d6c189SCody Peter Mello#Sorry about the first post, I'm not a bad awk programmer, just a tired one 43*e6d6c189SCody Peter Mello#:) 44*e6d6c189SCody Peter Mello# 45*e6d6c189SCody Peter Mello#chris 46*e6d6c189SCody Peter Mello# 47*e6d6c189SCody Peter Mello#> -----Original Message----- 48*e6d6c189SCody Peter Mello#> From: Darrel Hankerson [SMTP:hankedr@dms.auburn.edu] 49*e6d6c189SCody Peter Mello#> Sent: 18 May 1999 18:28 50*e6d6c189SCody Peter Mello#> To: christopher.procter@bt.com 51*e6d6c189SCody Peter Mello#> Subject: Re: Getline bug in Gawk 3.0.3 52*e6d6c189SCody Peter Mello#> 53*e6d6c189SCody Peter Mello#> Could you clarify? Your first script uses an apparently undefined 54*e6d6c189SCody Peter Mello#> variable f. 55*e6d6c189SCody Peter Mello#> 56*e6d6c189SCody Peter Mello#> 57*e6d6c189SCody Peter Mello#> christopher.procter@bt.com writes: 58*e6d6c189SCody Peter Mello#> 59*e6d6c189SCody Peter Mello#> BEGIN { 60*e6d6c189SCody Peter Mello#> for (i=1;i<10;i++){ 61*e6d6c189SCody Peter Mello#> while((getline < "hello.txt")>0){ 62*e6d6c189SCody Peter Mello#> print $0 63*e6d6c189SCody Peter Mello#> } 64*e6d6c189SCody Peter Mello#> close(f) 65*e6d6c189SCody Peter Mello#> } 66*e6d6c189SCody Peter Mello#> } 67*e6d6c189SCody Peter Mello#> 68*e6d6c189SCody Peter Mello#> refuses to close the file and so prints the contents of hello.txt just 69*e6d6c189SCody Peter Mello#> once. 70*e6d6c189SCody Peter Mello#> However:- 71*e6d6c189SCody Peter Mello#> 72*e6d6c189SCody Peter Mello#> BEGIN { 73*e6d6c189SCody Peter Mello#> f="hello.txt" 74*e6d6c189SCody Peter Mello#> for (i=1;i<10;i++){ 75*e6d6c189SCody Peter Mello#> while((getline < f)>0){ 76*e6d6c189SCody Peter Mello#> print $0 77*e6d6c189SCody Peter Mello#> } 78*e6d6c189SCody Peter Mello#> close(f) 79*e6d6c189SCody Peter Mello#> } 80*e6d6c189SCody Peter Mello#> } 81*e6d6c189SCody Peter Mello#> 82*e6d6c189SCody Peter Mello#> works as advertised (printing the contents of hello.txt 9 times) 83*e6d6c189SCody Peter Mello#> It seems like a bug in the close statement. 84*e6d6c189SCody Peter Mello#> 85*e6d6c189SCody Peter Mello#> -- 86*e6d6c189SCody Peter Mello#> --Darrel Hankerson hankedr@mail.auburn.edu 87*e6d6c189SCody Peter Mello# 88*e6d6c189SCody Peter Mello 89*e6d6c189SCody Peter Mello# srcdir is assigned on command line --- ADR 90*e6d6c189SCody Peter MelloEND { 91*e6d6c189SCody Peter Mello f = "redfilnm.in" 92*e6d6c189SCody Peter Mello for (i = 1; i < 10; i++){ 93*e6d6c189SCody Peter Mello while((getline < f) > 0){ 94*e6d6c189SCody Peter Mello print $0 95*e6d6c189SCody Peter Mello } 96*e6d6c189SCody Peter Mello close(f) 97*e6d6c189SCody Peter Mello } 98*e6d6c189SCody Peter Mello} 99