Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

GAWK : Turning a variable value into a variable name

Highlighted
Andrew Jewell
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
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[].