bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] gawk 4.1.3 gensub() warning


From: Jarno Suni
Subject: Re: [bug-gawk] gawk 4.1.3 gensub() warning
Date: Fri, 4 Sep 2015 11:05:47 +0300

On Thu, 3 Sep 2015 21:05:56 -0500
Ed Morton <address@hidden> wrote:

> Arnold - there's lots of things that are "wrong" but harmless so gawk
> just handles them sensibly without issuing warnings. For example,
> using an out of range starting index for substr():
> 
> $ awk 'BEGIN{print substr("foobar",-127,3)}'
> foo
> 
> $ awk 'BEGIN{print substr("foobar","",3)}'
> foo
> 
> is IMHO much more likely to indicate a real problem in your code than
> using "" instead of 1 in gensub() but in substr() gawk just quietly
> assumes you meant to use 1 instead of -127 or "" or whatever value a
> loop variable accidentally became. If substr() can continue to
> quietly assume that anything numerically less than 1 means 1, why
> can't gensub() continue to do that too after all of these years of
> doing so?

strtonum("g") == strtonum("") == 0, so it would be logical to treat ""
the same way as "g". Thus the warning is good IMO.

-- 
Jarno Ilari Suni - http://www.iki.fi/8/



reply via email to

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