Operating System - HP-UX
1748019 Members
4362 Online
108757 Solutions
New Discussion

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

 
Andrew Jewell
New Member

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 1
Dennis Handly
Acclaimed Contributor

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[].