pointers to variables ?

new topic     » topic index » view thread      » older message » newer message

Hi,

Another newbie question: are there pointers to variables, or is there any way to simulate them ?

For example, in gawk there are no pointers per se, but you can simulate them using the SYMTAB array:

my_list[1] = "test" 
var = "my_list"  
print SYMTAB[var][1] 
This last line is equivalent to
print my_list[1] 

In my gawk app I make extensive use of this ability as I need to manipulate lists whose name I only know at runtime, and I don't know that I'll be able to do this without pointers or something similar that enables me to access the symbol table.

For example, I read an input file that could contain the following lines defining three arrays, one read from a file and two defined inline:

datafile countries countries.list 
 
datalist departments 
HR 
Admin 
Facilities 
Services 
Sales 
IT 
EMT 
enddata 
 
datalist employees 
joe smith 
andy bloggs 
dave simpson 
ian jones 
wendy carter 
jane allenby 
enddata 

Later on in the same input file I may see a line saying

listitem employees 
and I have to be able to access the corresponding array to retrieve a random element.

At the moment I'm thinking that I may be able to use a map of lists as a workaround, but I haven't really gone into my existing gawk code to think it through, and if pointers do exist it would make things much more straightforward.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu