bug-gawk
[Top][All Lists]
Advanced

[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: Mon, 17 Jun 2019 10:43:13 +0300

Well, yes, I also think it's worthwhile to substitute the original example for 
something else, if it's considered.
Your last example is clear and simple, and it's similar to the example in the 
section "4.10.2 Using getline into a Variable".
If it is published instead of the original one, a reader could feel the 
difference between writing the result of "getline" into $0 and into a variable, 
having the same task in both cases.

P.S. My previous e-mail was corrupted.
_______________

Yours respectfully,
Mark Krauze


16.06.2019, 21:58, "Wolfgang Laun" <address@hidden>:
> Neither version is a good example for illustrating the getline function 
> because getline isn't necessary to solve the task and both contain too much 
> "noise".
>
> Although not very useful (is the present example "useful"?), this is short 
> and illustrates all the original example does.
> # swap successive lines
> {
>    line2 = $0
>    if (getline <= 0) {
>        print("unexpected EOF or error:", ERRNO) > "/dev/stderr"
>        exit
>    }
>    print $0
>    print line2
> }
>
> For removing /*...*/ with at most one /* per line, a more awk-ish program 
> (without getline) could be written. This is left as an exercise etc.
>
> -W
>
> On Sun, 16 Jun 2019 at 17:22, 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



reply via email to

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