array mystery

Peter M. Brigham, MD pmbrig at gmail.com
Thu May 3 17:46:13 EDT 2012


On May 3, 2012, at 3:10 PM, Ken Ray wrote:

> 
> On May 3, 2012, at 12:47 PM, Peter M. Brigham, MD wrote:
> 
>> I have a customprop, CYPdata, that is an array, each element of which is an array itself. I am scraping the data to build CYPdata from an HTML page on the web, and filling it via script by parsing the HTML. There is an odd bug that I'm trying to get to the bottom of, and something strange is happening when I do the following in a test button:
>> 
>> on mouseUp
>>  put the CYPdata of this stack into CYParray
>>  put CYParray["fluvoxamine"] into aFLV
>>  put CYParray["doxepin"] into aDOX
>>  put aFLV is an array into testFLV
>>  put aDOX is an array into testDOX
>>  breakpoint
>> end mouseUp
>> 
>> In the debugger variable pane at the breakpoint, expanding the array CYParray shows the keys, which are a whole list of drugs (as it should be), and each key/drug is indeed indicated as containing an array (with the little gray expansion triangle at the left). If I examine CYParray["fluvoxamine"] by clicking the expansion triangle, it shows the elements of that array, as expected. Same for CYParray["doxepin"]. The correct data is there in both cases. However, the aDOX variable does not display as an array (no expansion triangle) and testDOX = false, whereas aFLV is indeed an array, as displayed in the debugger and confirmed by testFLV = true.
>> 
>> What could be going on here? As it happens, the "doxepin" case is handled differently from the "fluvoxamine" case when I parse the HTML in loading the array, since they appear in slightly different contexts, so that must be the source of the difference, but how can the debugger show the "doxepin" array keys properly but somehow CYParray["doxepin"] not an array? Any ideas?
> 
> Peter, instead of trying to store multidimensional arrays "raw" in the custom property; can you use arrayEncode/arrayDecode? I think it might help eliminate issues; so assuming you parse the HTML and you have the data in a multidimensional array variable "CYParray", instead of doing:
> 
>  set the CYPdata of this stack to CYParray
> 
> do
> 
>  set the CYPdata of this stack to arrayEncode(CYParray)
> 
> … and then when you're ready to read it:
> 
> on mouseUp
>  put arrayDecode(the CYPdata of this stack) into CYParray  -- changed line
>  put CYParray["fluvoxamine"] into aFLV
>  put CYParray["doxepin"] into aDOX
>  put aFLV is an array into testFLV
>  put aDOX is an array into testDOX
>  breakpoint
> end mouseUp

Well, arrayEncoding/decoding doesn't change anything and neither does putting the text into a hidden field and then putting the text of the field back into a variable. The debugger still sees CYParray["doxepin"] as an array, with the correct keys and data visible, but
   put (CYParray["doxepin"] is an array) into testDOX
still gives testDOX = false, and 
   put CYParray["doxepin"]["3A456"] into shouldBeX
gives empty, when it should be "x". The same construction for CYParray["fluvoxamine"] works as expected.

I'm stumped. Looks as if I'll have to try a whole different approach, which I can do, but I'm very troubled by not understanding at all what is going on. It makes no sense. I can tolerate not understanding something if I have some glimmerings and know that I could get to the bottom of it if I work at it, but I hate not having a clue at all.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig





More information about the Use-livecode mailing list