[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Suggestion to simplify one of the examples
From: |
M |
Subject: |
Re: [bug-gawk] Suggestion to simplify one of the examples |
Date: |
Thu, 20 Jun 2019 21:14:41 +0300 |
Oh, some troubles with a mail client. I'm sorry for posting a duplicate.
20.06.2019, 18:08, "M" <address@hidden>:
> You are welcome! And it seems that after these changes the second exercise
> from "4.15 Exercises" is out-of-date.
>
> _______________
>
> Yours respectfully,
> Mark Krauze
>
> 18.06.2019, 20:27, "address@hidden" <address@hidden>:
>> Thanks for the suggested change. That along with making the first 'if'
>> into a 'while' improves the program a lot. I will be pushing changes
>> to Git shortly.
>>
>> Thanks,
>>
>> Arnold
>>
>> M <address@hidden> wrote:
>>
>>> When rereading the last version of the manual, I noticed vague operations
>>> with a variable "j" in the example "Remove text between /* and */,
>>> inclusive" (4.10.1 Using getline with No Arguments).
>>> If we admit that there are some drawbacks (e.g. the program doesn't work
>>> if one comment ends and another begins on the same line, it produces
>>> "substr" boundary warnings, and so on), why don't we write in this way:
>>>
>>> # Remove text between /* and */, inclusive
>>> {
>>> if ((i = index($0, "/*")) != 0) {
>>> out = substr($0, 1, i - 1) # leading part of the string
>>> rest = substr($0, i + 2) # ... */ ...
>>> while ((j = index(rest, "*/")) == 0) { # is */ in trailing part?
>>> # get more text
>>> if (getline <= 0) {
>>> print("unexpected EOF or error:", ERRNO) > "/dev/stderr"
>>> exit
>>> }
>>> # build up the line using string concatenation
>>> rest = rest $0
>>> }
>>> rest = substr(rest, j + 2) # remove comment
>>> # build up the output line using string concatenation
>>> $0 = out rest
>>> }
>>> print $0
>>> }
>>>
>>> ##############################
>>>
>>> ?
>>>
>>> Indeed, the goal is to show the usage of "getline", not to demonstrate
>>> e.g. control statements or "break" statement.
>>>
>>> _______________
>>>
>>> Yours respectfully,
>>> Mark Krauze