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: arnold
Subject: Re: [bug-gawk] Suggestion to simplify one of the examples
Date: Tue, 18 Jun 2019 11:01:01 -0600
User-agent: Heirloom mailx 12.5 7/5/10

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
>
>



reply via email to

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