bug-gawk
[Top][All Lists]
Advanced

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

Re: lint warning: unnecessary mixing of `>' and `>>'


From: Manuel Collado
Subject: Re: lint warning: unnecessary mixing of `>' and `>>'
Date: Mon, 23 Oct 2023 13:07:58 +0200
User-agent: Mozilla Thunderbird

El 21/10/23 a las 20:24, Wolfgang Laun escribió:
On Sat, 21 Oct 2023 at 20:04, <arnold@skeeve.com> wrote:
[snip ]

I have rewritten the paragraphs
in that section of the manual to make this more clear. New text
is below.  I don't see a need to change the lint warning itself.

[snip]

You should be consistent and always use the same operator for all output
to the same file. (You can mix @samp{>} and @samp{>>}, and nothing bad
will happen, but mixing the operators is considered to be bad style in
@command{awk}. If invoked with the @option{--lint} option, @command{gawk}
issues a warning when it encounters both operators being used for the
same open file.)


It's not unusual that the same program could be used for writing a file
from scratch, or to append to it.
Except for the first print statement (i.e., the open), the code would be
the same. How would I
write it in order to remain consistent and in good style?

A possible rule of thumb could be: "Always use '>' except when '>>' is really necessary".

Assume some code that rewrites a file from scratch (using '>') and now you want to use it to append more data. Perhaps it should be possible to keep the original code unchanged (with '>') and just add an initial statement to open the file in append mode: printf("") >> "some_file".

Of course --lint will warn about '>' and '>>' mix, but in this particular case it is not bad style, IMHO.

Just my 2c.

--
Manuel Collado - http://mcollado.z15.es



reply via email to

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