bug? or how to distinguish between a Hash and an array of Hashes ? [message #83397] |
Mon, 04 March 2013 06:16 |
markb77
Messages: 217 Registered: July 2006
|
Senior Member |
|
|
hi,
Is there any way to distinguish between a hash object and an array of
hash objects? Normally I use the SIZE() function to test for data
type, etc. However, in this case, SIZE() doesn't appear to be able to
distinguish between a single, scalar HASH, and an array of HASHes.
Consider the following test code:
pro test
a = hash('first', 1, 'second', 2)
b = hash('third', 3, 'fourth', 4, 'fifth', 5)
print, 'Output of SIZE() for a HASH varible: ', size(a)
c = [a,b]
print, 'Output of SIZE() for an array of HASH variables: ',
size(c)
end
this gives the following output:
Output of SIZE() for a HASH varible: 1
2 11 2
Output of SIZE() for an array of HASH variables:
1 2 11 2
so.. identical. It appears that when you pass a scalar HASH object to
SIZE(), it returns the number of elements in the HASH, and the
N_Dimensions fields shows it as being a 1D array, rather than a
scalar.
Is there another way to distinguish between the two cases? This
problem would apply to LIST objects as well.
thanks!
Mark
|
|
|