string to variable?
denney at seas.upenn.edu
Mon Sep 4 13:00:13 CDT 2006
On Mon, 4 Sep 2006, the_verge wrote:
> I was wondering if there is a way to assign a value to a variable, and then
> construct a string with the same characters as the variable, and then use it
> to access the value of the original variable. For Example:
> thing_a = 2;
> x = "thing_a";
> %code here to merge the string "thing_a" with the variable thing_a
> My hope is that running this script would return
> x = 2
> Is there a way to do this?
It sounds like you're wanting to do something that would work better with
structures (eval usually ends up causing headaches later). Might
something like this work for you:
string = "thing_a";
value = 2;
x.(string) = value;
Now, x.thing_a is set equal to 2.
"You couldn't fill a 128-bit storage pool without boiling the oceans."
-- Jeff Bonwick, http://www.sun.com/2004-0914/feature/
More information about the Help-octave