array mystery

Peter M. Brigham, MD pmbrig at gmail.com
Thu May 3 16:32:59 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
> 
> Ken Ray

I'll try that. However, I'm suspecting a problem with the raw data fetched from the webpage, since after doing several filters on a section of the HTML containing "doxepin" I was left with something that looked like the correct list of meds, one to a line, but with some empty lines. When I tried to "filter tList without empty" it was left unchanged, and even doing a descending repeat loop to delete empty lines it was unchanged. I had to resort to a descending repeat loop checking if the number of words of line n of tList = 0 and deleting those. There appeared to be no tabs or detectable characters in tList (I would not expect tabs anyway in a distillation of HTMLtext). But there's something squirrely about the text I'm fetching. I'm wondering if it's related to line termination characters in some way, so I may try putting the raw text into a hidden field and then taking it out again before parsing it, to let the LC engine handle the cross-platform EOL/CR/LF complexities. But I'll try the arrayEncode/arrayDecode thing too.

-- Peter

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





More information about the use-livecode mailing list