help-gawk
[Top][All Lists]
Advanced

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

Re: How to convert a string to strnum?


From: Neil R. Ormos
Subject: Re: How to convert a string to strnum?
Date: Sun, 5 Sep 2021 13:32:56 -0500 (CDT)

Peng Yu wrote:
> Neil R. Ormos wrote:
>> Peng Yu wrote:
>>> Neil R. Ormos wrote:
>>>> Peng Yu wrote:

>>>>> I can only convert a string to a number. But
>>>>> I don't find a way to convert a string to a
>>>>> strnum. Is there a way to do so?

>>>> [Citing the manual:]
>>>> | [...] Fields, getline input, FILENAME, ARGV
>>>> | elements, ENVIRON elements, and the elements of
>>>> | an array created by match(), split(), and
>>>> | patsplit() that are numeric strings have the
>>>> | strnum attribute. [...]

>>> It sounds like a function named like
>>> str2strnum(), other a hack using match(), is
>>> more intuitive.

>> Attention is yet again drawn to the manual.
>> Section 9.2 (currently), entitled "User-Defined
>> Functions," explains how one can define a
>> function and assign a nearly arbitrary name to
>> it.

>> It is observed that the name "str2strnum" is
>> available for use as a user-defined function in
>> gawk version 5.1.0.

> My point is that it may be better to include
> such a function by default instead of relying on
> users to repetitively define it on their own.

No one is "relying on users to repetitively
define" anything.

For the rare user who is dissatisfied with calling
such existing functions as split() and match() to
obtain a value that may have the strnum attribute,
in a way definitively explained in the manual,
because the function is being called to obtain an
effect that is not literally described by the
function's name, gawk provides the user-defined
function facility through which the user may
trivially obtain a wrapper function that produces
the same result and bears the name he or she
prefers.  The @include facility and the -i option
allow such user to avoid essentially all the
burden of "repetitively defining" the function.



reply via email to

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