Source-Changes-D archive

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

Re: CVS commit: src/external/historical/nawk/bin



Am 05.07.2022 um 02:16 schrieb Valery Ushakov:
Posix has the echo example as:

   BEGIN  {
           for (i = 1; i < ARGC; ++i)
           printf("%s%s", ARGV[i], i==ARGC-1?"\n":" ")
   }

which I would still consider ugly :).  I would rather use instead:

   BEGIN { for (i = 1; i < ARGC; ++i) $i = ARGV[i]; print }

that, as a bonus, demonstrates $var field references (that the current
man page doesn't mention at all) and the magic $0 "reassembly".

Now that looks clean and idiomatic.

Anyway, I was wrong about POSIX - I somehow managed to screw up my
search and missed the passage that specifies it:

   If an awk program consists of only actions with the pattern BEGIN,
   and the BEGIN action contains no getline function, awk shall exit
   without reading its input when the last statement in the last BEGIN
   action is executed. If an awk program consists of only actions with
   the pattern END or only actions with the patterns BEGIN and END, the
   input shall be read before the statements in the END actions are
   executed.

Hmmm, strange that we both missed this part on the first reading, even
though it seems obvious now.  I remember having searched for BEGIN,
which would have led me to this paragraph, but I somehow skipped it when
trying to prove my point.

Roland


Home | Main Index | Thread Index | Old Index