Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GAWK API Question #1

33 views
Skip to first unread message

Kenny McCormack

unread,
Jan 15, 2015, 11:38:30 AM1/15/15
to
In working my way through the sample code in the GAWK distribution
while developing my latest extension library, I noticed that, to access an
AWK array passed into the extension, some of the examples use a method
where the user passes in a string containing the name of the array (the
specific example was an array called "pets" - which contains a list of pet
names - and the user passes "pets"), while others have the user pass in the
array itself. When the first method is used (passing in a string), the
extension has to parse out the string, then pass that string to a "symlookup"
function (whose name escapes me at the moment) to get to the array, then
use the array. Whereas, if the second method is used, the lookup step is
eliminated (you can get to the array directly from the passed arg).

So, the obvious question is: Why would you ever choose to use the first
method? Is there any advantage to it? Is there any reason it is used in
some of the example code?



--
"There's no chance that the iPhone is going to get any significant market share. No chance." - Steve Ballmer

David LaRue

unread,
Jan 15, 2015, 11:58:48 AM1/15/15
to
gaz...@shell.xmission.com (Kenny McCormack) wrote in
news:m98qe5$i2m$1...@news.xmission.com:

> In working my way through the sample code in the GAWK distribution
> while developing my latest extension library, I noticed that, to
> access an AWK array passed into the extension, some of the examples
> use a method where the user passes in a string containing the name of
> the array (the specific example was an array called "pets" - which
> contains a list of pet names - and the user passes "pets"), while
> others have the user pass in the array itself. When the first method
> is used (passing in a string), the extension has to parse out the
> string, then pass that string to a "symlookup" function (whose name
> escapes me at the moment) to get to the array, then use the array.
> Whereas, if the second method is used, the lookup step is eliminated
> (you can get to the array directly from the passed arg).
>
> So, the obvious question is: Why would you ever choose to use the
> first method? Is there any advantage to it? Is there any reason it
> is used in some of the example code?

Hello Kenny,

Consider a GAWK application that reads a document and accumulates
several tables of information about it. Perhaps as a command line
parameter or other input the resulting report oly displays certan
information. In this way you could display just information that you
were looking for or the entire contents. The first method could be used
to generalize the lookup.

The second method could be used but it required more code and updates to
the code when new tables are gathered.

David

Kenny McCormack

unread,
Jan 15, 2015, 12:09:33 PM1/15/15
to
In article <XnsA42379C9CA0...@94.75.214.90>,
David LaRue <huey...@gte.net> wrote:
...
>Consider a GAWK application that reads a document and accumulates
>several tables of information about it. Perhaps as a command line
>parameter or other input the resulting report oly displays certan
>information. In this way you could display just information that you
>were looking for or the entire contents. The first method could be used
>to generalize the lookup.
>
>The second method could be used but it required more code and updates to
>the code when new tables are gathered.

Yeah, I get ya. The idea is that the name of the array to pass into the
extension could be variable (i.e., determined at runtime). In which case
that method would be needed.

I guess my point is that it seemed strange to see that method used in
the sample code, since there was only one array in scope, although I
suppose it may have been done for exactly that reason - to illustrate how
one might do such a thing should the need arise.

--
"Everything Roy (aka, AU8YOG) touches turns to crap."
--citizens of alt.obituaries--
0 new messages