Modifying Arrays and Structures in HASH's (hint: you can't) [message #79688] |
Thu, 22 March 2012 14:58  |
JDS
Messages: 94 Registered: March 2009
|
Member |
|
|
HASH's are nice in that they can contain any variable type, and make iterating over deeply nested data structure more humane. On the other hand, their limitations as separate standalone objects, and not as a deeper feature of the language, are very apparent, for example, when you'd like to alter something inside of them:
IDL> h=hash('a',{b:1,c:2})
IDL> print,h['a'].b
1
IDL> h['a'].b=2
% Attempt to store into an expression: Structure reference.
% Execution halted at: $MAIN$ 84
The same happens for arrays stored in hashes. You're required to copy the entire array or structure out, modify it, then copy it back into the hash (remind anyone of the old days and widget state?). If it were possible for HASH dereferencing to return true IDL variable references, they would be far more useful.
Any workarounds to this "write-only" HASH behavior (other than, say, "use a pointer")?
JD
|
|
|