Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

GAWK : Turning a variable value into a variable name

Highlighted
Occasional Visitor

GAWK : Turning a variable value into a variable name

I need to fill in the middle statement in the following GAWK script:

X = "foo"
# something like @X = 7
assert( foo == 7 )

in perl I'd just use $$X. Is there a way to do this in GAWK?
1 REPLY
Acclaimed Contributor [Founder]

Re: GAWK : Turning a variable value into a variable name

I don't know of any. You could use associative arrays:
X = "foo"
mapVar[X] = 7
assert(mapVar["foo"] == 7)

I.e. if you want to do the indirection, you always have to use mapVar[].