bug-gnu-utils
[Top][All Lists]
Advanced

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

gawk devel.- processing arrays of arrays


From: Manuel Collado
Subject: gawk devel.- processing arrays of arrays
Date: Mon, 13 Dec 2010 13:54:57 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.2.9) Gecko/20100825 Thunderbird/3.1.3

Reposted (sorry, already sent to the wrong address - please forgive me if you get duplicates)
---------------------

The forthcoming gawk 4.0 supports arrays of arrays. But it seems that there is no way to write generic code that process all (scalar) elements of a generalized array without knowing its structure in advance. The expected recursive construction could be:

function process_array( a ) {
   for (i in a) {
      if (isarray(a[i])) {
         process_array( a[i] )
      } else {
         ... process a[i] as scalar ...
      }
   }
}

Regrettably, there is no 'isarray()' primitive. I've thought about using 'length(array)', but it is not array-specific (gives string length for scalars).

So please consider adding a new primitive to gawk-4.x. Perhaps either:
- isarray(x), or
- alength(x)
x been a scalar or an array - alength(scalar) should give a negative value.

The second alternative could render the length(array) extension unnecessary.

Am I missing something already available? Is there another way of enumerating all final elements of a multi-array without knowing its particular structure in advance?

Regards.

PS: Would it be appropriate to discuss this issue in comp.lang.awk?
--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado




reply via email to

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