Thank you Isaiah and Patrick. The source is a Dict{ASCIIstring, Any}. From your answers I realized, I can instead use Dict{Symbol, Any} as the source and then use either Don's or Isaiah's syntax.
Yes, I was thinking that may be I should use a Dict. But then I would have to use Dict{ASCIIstring, Any} type. I was not sure (because I don't know about these things) whether that would affect the performance adversely (because of the Any). While Dict{ASCIIstring, Any} is a source that is used to change *inst, inst *is used multiple times in the program. Once it's value is changed, its type is known completely when it is used those multiple times. On Sunday, September 14, 2014 11:09:56 AM UTC-4, Patrick O'Leary wrote: > > On Saturday, September 13, 2014 6:47:46 PM UTC-5, curiou...@gmail.com > wrote: >> >> However, suppose the field that has to be changed is determined by the >> program. Say, I have, >> >> varToChange = "numLines" >> >> How can I use *varToChange* to change the value of *numLines* in *inst*? >> > > Here are a couple of alternatives. > > Depending on the source of your "numLines", you can assign the symbol > directly, rather than via a string and a call to symbol(), combining it > with either Don or Isaiah's syntaxes: > > varToChange = :numLines > > If this is the sort of thing you find you are doing often, a composite > type may not be the correct data structure for your application. Consider a > Dict: > > inst = Dict{String, Any}() > inst["numLines"] = 10 > inst["avgLength"] = 8.5 > inst[varToChange] = 20 > > Patrick >