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: Andrew J. Schorr
Subject: Re: [bug-gawk] Function call bug in GNU Awk 3.1.6
Date: Tue, 15 Nov 2011 19:14:17 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

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]