Blame test/redfilnm.awk

Packit 575503
#Date: Tue, 18 May 1999 12:48:07 -0500 (CDT)
Packit 575503
#From: Darrel Hankerson <hankedr@dms.auburn.edu>
Packit 575503
#To: arnold@gnu.org
Packit 575503
#Subject: [christopher.procter@bt.com: RE: Getline bug in Gawk 3.0.3]
Packit 575503
#
Packit 575503
#Here's a reply that came directly to me.  --darrel
Packit 575503
#
Packit 575503
#
Packit 575503
#From: christopher.procter@bt.com
Packit 575503
#To: hankedr@dms.auburn.edu
Packit 575503
#Subject: RE: Getline bug in Gawk 3.0.3
Packit 575503
#Date: Tue, 18 May 1999 18:42:28 +0100
Packit 575503
#
Packit 575503
#Sorry that was me getting carried away and cut and pasting the wrong thing
Packit 575503
#into my email
Packit 575503
#
Packit 575503
#The real problem seems to be that :
Packit 575503
#BEGIN {
Packit 575503
#for (i=1;i<10;i++){
Packit 575503
#	while((getline < "hello.txt")>0){
Packit 575503
# 		print $0
Packit 575503
#		}
Packit 575503
# 	close("hello.txt")
Packit 575503
#	}
Packit 575503
#}
Packit 575503
#works (printing the contents of hello.txt 9 times), where as:-
Packit 575503
#
Packit 575503
#END{
Packit 575503
#for (i=1;i<10;i++){
Packit 575503
#	while((getline < "hello.txt")>0){
Packit 575503
# 		print $0
Packit 575503
#		}
Packit 575503
# 	close("hello.txt")
Packit 575503
#	}
Packit 575503
#}
Packit 575503
#
Packit 575503
#doesn't, (it prints out hello.txt once followed by the iteration numbers
Packit 575503
#from 1 to 9).
Packit 575503
#The only difference is that one is in the BEGIN block and one in the END
Packit 575503
#block.
Packit 575503
#
Packit 575503
#Sorry about the first post, I'm not a bad awk programmer, just a tired one
Packit 575503
#:)
Packit 575503
#
Packit 575503
#chris
Packit 575503
#
Packit 575503
#> -----Original Message-----
Packit 575503
#> From:	Darrel Hankerson [SMTP:hankedr@dms.auburn.edu]
Packit 575503
#> Sent:	18 May 1999 18:28
Packit 575503
#> To:	christopher.procter@bt.com
Packit 575503
#> Subject:	Re: Getline bug in Gawk 3.0.3
Packit 575503
#> 
Packit 575503
#> Could you clarify?  Your first script uses an apparently undefined
Packit 575503
#> variable f.
Packit 575503
#> 
Packit 575503
#> 
Packit 575503
#> christopher.procter@bt.com writes:
Packit 575503
#> 
Packit 575503
#>    BEGIN {
Packit 575503
#>    for (i=1;i<10;i++){
Packit 575503
#>    while((getline < "hello.txt")>0){
Packit 575503
#>      print $0
Packit 575503
#>    }
Packit 575503
#>      close(f)
Packit 575503
#>    }
Packit 575503
#>    }
Packit 575503
#> 
Packit 575503
#>    refuses to close the file and so prints the contents of hello.txt just
Packit 575503
#> once.
Packit 575503
#>    However:-
Packit 575503
#> 
Packit 575503
#>    BEGIN {
Packit 575503
#>    f="hello.txt"
Packit 575503
#>    for (i=1;i<10;i++){
Packit 575503
#>    while((getline < f)>0){
Packit 575503
#>      print $0
Packit 575503
#>    }
Packit 575503
#>      close(f)
Packit 575503
#>    }
Packit 575503
#>    }
Packit 575503
#> 
Packit 575503
#>    works as advertised (printing the contents of hello.txt 9 times)
Packit 575503
#>    It seems like a bug in the close statement.
Packit 575503
#> 
Packit 575503
#> -- 
Packit 575503
#> --Darrel Hankerson hankedr@mail.auburn.edu
Packit 575503
#
Packit 575503
Packit 575503
# srcdir is assigned on command line --- ADR
Packit 575503
END {
Packit 575503
	f = srcdir "/redfilnm.in"
Packit 575503
	for (i = 1; i < 10; i++){
Packit 575503
		while((getline < f) > 0){
Packit 575503
 			print $0
Packit 575503
		}
Packit 575503
 		close(f)
Packit 575503
	}
Packit 575503
}