Home > Archive > AWK > September 2004 > array name in a variable
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
array name in a variable
|
|
|
| Is it possible to put the array name in a var and use it ?
ex:
$1="array"
$1[3] = 4
--
--
I use PGP. Ask for my key if interested.
-
| |
| Stepan Kasal 2004-09-16, 8:10 pm |
| Hi,
In article <ci53re$5t2$1@le1.cs.unibo.it>, Tony wrote:
> Is it possible to put the array name in a var and use it ?
>
> ex:
> $1="array"
> $1[3] = 4
with most awks it's not possible. The AWK, mawk, gawk--all compile
the program at the beginning to an internal form and you cannot invoke
the parser later on. But you can use shell, of course, eg:
arrname=array
awk 'BEGIN {
....
'$arrname'[3] = 4
....
HTH,
Stepan Kasal
| |
|
| thank you very much
--
--
I use PGP/GPG. Ask for my key if interested.
-
"Stepan Kasal" <kasal@ucw.cz> ha scritto nel messaggio
news:slrnckdehf.un6.kasal@matsrv.math.cas.cz...
> Hi,
>
> In article <ci53re$5t2$1@le1.cs.unibo.it>, Tony wrote:
>
> with most awks it's not possible. The AWK, mawk, gawk--all compile
> the program at the beginning to an internal form and you cannot invoke
> the parser later on. But you can use shell, of course, eg:
>
> arrname=array
> awk 'BEGIN {
> ...
> '$arrname'[3] = 4
> ...
>
> HTH,
> Stepan Kasal
| |
| glen herrmannsfeldt 2004-09-30, 2:55 am |
| Tony wrote:
> Is it possible to put the array name in a var and use it ?
>
> ex:
> $1="array"
> $1[3] = 4
Use a two dimensional array where $1 is the first element.
$1="array";
x[$1,3]=4;
-- glen
|
|
|
|
|