[Top][All Lists]

[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: Sun, 12 Dec 2010 23:15:42 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv: Gecko/20100825 Thunderbird/3.1.3

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 array_process( a ) {
   for (i in a) {
      if (isarray(a[i])) {
         array_process( 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?


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]