VARA1, VARB2, VARC8,... [message #24190] |
Thu, 15 March 2001 20:02  |
Mark Chan
Messages: 24 Registered: November 2000
|
Junior Member |
|
|
Example:
If ('x' eq 'a1') then vara1=..... etc
If ('x' eq 'b2') then varb2=.... etc
I will like to create variable names which is a combination of two separate
segments of strings. Is there an easy way to do so?
Thanks,
Mark Chan
|
|
|
Re: VARA1, VARB2, VARC8,... [message #24253 is a reply to message #24190] |
Mon, 19 March 2001 14:02  |
Pavel A. Romashkin
Messages: 531 Registered: November 2000
|
Senior Member |
|
|
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.
Cheers,
Pavel
Disclaimer : The above advice may have nothing to do with what the
question was about :-)
|
|
|