bug-gawk
[Top][All Lists]
Advanced

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

Re: Fwd: gawk: numeric comparison on 'sub()' resulted ${n} vars does not


From: Andrew J. Schorr
Subject: Re: Fwd: gawk: numeric comparison on 'sub()' resulted ${n} vars does not work properly
Date: Sat, 8 Feb 2020 13:55:44 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

On Sat, Feb 08, 2020 at 10:33:50AM -0700, Stephen Dowdy wrote:
> This bug i filed for 'mawk' (via Debian) also affects 'gawk' (hope you don't 
> mind the cut/paste)
> 
> Bug#950894: Acknowledgement (mawk: numeric comparison on 'sub()' resulted 
> ${n} vars does not work properly)
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=950894

The problem you're encountering is that the call to sub changes the character
of $1 from strnum to string. For example:

bash-4.2$ echo 55 | ./gawk '{print typeof($1); sub("5","",$1); print 
typeof($1); if ($1>40) printf("[%s][%d]\n",$1,$1)}
'
strnum
string
[5][5]

So you're getting a string comparison. The simple fix is to force a numeric 
comparision,
like so:

bash-4.2$ echo 55 | ./gawk '{print typeof($1); sub("5","",$1); print 
typeof($1); if ($1+0>40) printf("[%s][%d]\n",$1,$1)}
'
strnum
string

Regards,
Andy



reply via email to

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