[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Lint warning when passing strnum to 'length'
From: |
Timothy Sample |
Subject: |
Lint warning when passing strnum to 'length' |
Date: |
Mon, 14 Mar 2022 14:09:32 -0600 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
Hello!
While using ‘gawk --lint’ just now, I received many warnings:
warning: length: received non-string argument
However, what I am passing is an “strnum”. Even though the input string
looks like a number, I’m happy to treat it like a string, which makes
the lint warning net very useful to me.
The following demonstrates the behaviour:
echo 123 | gawk --lint '{ print(length($1)); }'
(BTW, this is on GNU Awk 5.1.0 from Guix.)
There’s every possibility that this is intentional, but my naïve
expectation is that Gawk should be okay with passing an strnum to
‘length’. I am aware that I can suppress the warning by forcing Gawk to
treat the input as a string (‘length($1 "")’), but I’m not sure I should
have to. Thoughts?
In general, I am very impressed with the Gawk linter and also the
“--posix” flag, which help me write cleaner, more portable Awk
programs. Thank you very much!
-- Tim
- Lint warning when passing strnum to 'length',
Timothy Sample <=