In article
<853cada4-f51a-47b8-b39e-ea056c00d1d4@[EMAIL PROTECTED]
>,
mjc <mjcohen@[EMAIL PROTECTED]
> wrote:
>On Mar 29, 2:18 pm, Ed Morton <mor...@[EMAIL PROTECTED]
> wrote:
>>
>....
>> What contortions? Could you give a small example of the problem?
>>
>.....
>> Ed.
>
>I wrote a program in gawk to compare the results of a computation
>(written in assembly language with debugging info) with a simulation
>of the computation. In addition, the program also read the assembly
>listing so it would know what debugging info could be written and read
>its own source so it would know what debugging info was being looked
>for.
Basically, getline is only _needed_ when you are reading more than one
file at a time (i.e., "in parallel"). Now, having said that, some
people find its use (in those cases where it is not necessary) to be
aesthetically appealing - and others don't. Obviously, there's no
accounting for taste. I agree with Ed's basic position on the matter,
which is that using getline appeals to people who don't quite get "awk
qua awk".
Your example certainly fits the classic "people think they need getline,
but they don't" archetype. That is, your program should (in the Ed/Kenny
sense of the word "should") be written:
ARGIND == 1 {
# Do stuff for file 1
next
}
ARGIND == 2 {
# Do stuff for file 2
next
}
ARGIND == 3 {
# Do stuff for file 3
next
}
{
# else do stuff for file 4
# Note that for this, the last file, you can also use all the usual
# AWK pattern/action stuff
}
Note: I hope I got the ARGIND stuff right (ARGIND is, AFAIK,
gawk-specific). I normally use TAWK, which has a variable called ARGI,
which is the same as gawk's ARGIND, except that it is higher by one (so
the first file is: ARGI == 2 {})
Notes:
1) Yes, it is unfortunate that you can only use the "automatic patterns"
in the last file. But this is (obviously) the same as if using getline.
2) The real point of using the above style in place of getline is that
you specify the files to be read on the command line, rather than
hard-coding them into the script. This is a Good Thing, although many
see it as a minus at first sight.


|