help-gawk
[Top][All Lists]
Advanced

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

Re: warning: regexp constant for parameter #1 yields boolean value


From: Neil R. Ormos
Subject: Re: warning: regexp constant for parameter #1 yields boolean value
Date: Thu, 4 Aug 2022 11:31:47 -0500 (CDT)

J Naman wrote:

> I am sorry, I do not understand what this
> warning means in this case.  code:

> r0=gensub(/([0-9])[,]([0-9])/,"\\1\\2","g",r0);

> warning: regexp constant for parameter #1 yields boolean value

> # want "1,234,567" => "1234567"

What version of gawk are you running?  I couldn't reproduce the problem on the 
several gawk versions I have (various 3.x, 4.x, and 5.x, but not the very 
latest).

I think that warning is supposed to be emitted when you try to pass a standard 
regexp constant to a user-defined function.  In that case, I think there's an 
implicit pattern-style evaluation against $0, which yields a boolean, and which 
is probably not what the user expects. [*]

[*] Manual Sec. 6.1.2.1: "When a regexp constant
    appears by itself, it has the same meaning as
    if it appeared in a pattern 
    (i.e., '($0 ~ /foo/)')."  
    See also the last part of that section that
    explains the possible confusion.

But that doesn't explain why you are receiving the message in the context of 
gensub(), which is not user-defined, and for which the first parameter is 
permitted to be a "standard" regular expression constant.

Have you tried prepending @ to the regexp to make it strongly typed?

I suspect this is a bug.



reply via email to

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