[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: VARA1, VARB2, VARC8,...

I have had this same question when I went to IDL from Igor Pro, where
descriptive variable names are imperative not only for the readability
of the code, but even more so for its functionality :-(

I was told by one of the RSI folks that this approach is flawed, if you
think about it. Instead, you want to use a structure that is stored in a
generic variable, and place a descriptive name in one of the structure's fields:

temp = {name: '', data: ptr_new(/allocate)}
all_variables = replicate(temp, num_variables)
all_variables[0].name = 'var'+x
*(all_variables[0].data) = ....

instead of

If ('x' eq 'a1') then vara1=..... etc

If ('x' eq 'b2') then varb2=.... etc

which, BTW, will never work, because the string 'x' will never be equal
to the string 'a1' anyway.

This way, you don't have to *find* how to access variables you
dynamically name, when you need to work with them later. All you do then
is search the structure.

Disclaimer : The above advice may have nothing to do with what the
question was about :-)