bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Function call bug in GNU Awk 3.1.6


From: Aharon Robbins
Subject: Re: [bug-gawk] Function call bug in GNU Awk 3.1.6
Date: Wed, 16 Nov 2011 18:59:10 +0200
User-agent: Heirloom mailx 12.4 7/29/08

Indeed, adding a close does the trick.

Arnold

> Date: Tue, 15 Nov 2011 19:14:17 -0500
> From: "Andrew J. Schorr" <address@hidden>
> To: Louis Jean-Richard <address@hidden>
> Cc: address@hidden
> Subject: Re: [bug-gawk] Function call bug in GNU Awk 3.1.6
>
> On Tue, Nov 15, 2011 at 05:08:43PM +0100, Louis Jean-Richard wrote:
> > Here after a simplified down awk program that misbehaves:
> >     awk --version
> >     awk  '#
> >         function indexKey(data) {
> >             "echo \x22" "30c9a839" data "\x22" | getline key
> >             return substr(key, 1, 32)
> >             }
> >         BEGIN {
> >             TW = sprintf("%032d756f36b", 1357)
> >             TWK = indexKey(TW)
> >             #
> >             keyAAAA =  indexKey("AAAA-" TWK)
> >             keyBBBB =  indexKey("BBBB-" TWK)
> >             keyCCCC =  indexKey("CCCC-" TWK)
> > 
> >             print "AAAA  " keyAAAA
> >             print "AAAA- " indexKey("AAAA-23056")
> >             print "BBBB  " keyBBBB
> >             print "CCCC  " keyCCCC
> >             print "    The following four lines should be the same
> > as the four preceding."
> >             print "AAAA  " indexKey("AAAA-" TWK)
> >             print "AAAA- " indexKey("AAAA-23056")
> >             print "BBBB  " indexKey("BBBB-" TWK)
> >             print "CCCC  " indexKey("CCCC-" TWK)
> >             }
> >         '
>
> I think you need to close the command.  Please try this
> version of the indexKey function:
>
>         function indexKey(data,  cmd,key) {
>             cmd = ("echo \x22" "30c9a839" data "\x22")
>             cmd | getline key
>             close(cmd)
>             return substr(key, 1, 32)
>       }
>
> Without the close, subsequent getline calls for the same value of data should
> return an empty string (since the echo generates no further output).
>
> Regards,
> Andy
>



reply via email to

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