comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » VARA1, VARB2, VARC8,...
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
VARA1, VARB2, VARC8,... [message #24190] Thu, 15 March 2001 20:02 Go to next message
Mark Chan is currently offline  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 Go to previous message
Pavel A. Romashkin is currently offline  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 :-)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Whats up in opening files: Unix vs. Windows
Next Topic: Filter

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:21:08 PDT 2025

Total time taken to generate the page: 0.00642 seconds