On May 10, 2012, at 5:49 PM, Bob Sneidar wrote:

> I just forwarded an email Trevor sent to the list some time ago with the code 
> in it. 
> 
> Bob
> 
> 
> On May 10, 2012, at 2:34 PM, Peter M. Brigham, MD wrote:
> 
>> It was apparently part of Trevor's sqlYoga, supposedly made available now as 
>> an opensource utility handler, but I can't find it. The Nabble archives show 
>> an "altPrintKeys()" function but the output is not a readable display of the 
>> structure of an array, it's designed for utility work in massaging arrays. 
>> I'd like to get hold of the original printKeys() handler somewhere. Where 
>> can I find it?

In case anyone else wants it, I'm posting below a slightly modified version of 
the function, renamed "displayArray" to distinguish it from the variants that 
Bob has posted for utility work. This version simply allows you to look at the 
contents of an array in outline form, which makes the structure of the array 
quite clear on inspection.

-- Peter

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

------

function displayArray @pArray, pFullData, pDimension
   -- displays an array as an outline-style list
   -- most useful for multidimensional arrays, to see the structure
   -- if an element of the array contains more than one line,
   --    the first line only will be displayed (less confusing to look at)
   -- if you want to see the full data then pass pFullData = true
   -- pDimension is an internally used parameter
   -- pArray is referenced to avoid duplicating large arrays, but
   --    the array is not altered by this function
   
   -- call it like this: put displayArray(tArray) into fld "peruse"
   
   -- requires spaces()
   
   if pDimension is empty then put 0 into pDimension
   if pFullData = empty then put false into pFullData
   put the keys of pArray into theKeys
   if line 1 of theKeys is a number then
      sort theKeys numeric
   else
      sort theKeys
   end if
   repeat for each line theKey in theKeys
      if pArray[theKey] is an array then
         put spaces(pDimension * 3) & theKey & cr after theText
         put pArray[theKey] into theTempArray
         put displayArray(theTempArray, pFullData, pDimension + 1) after theText
      else
         if pFullData then
            put spaces(pDimension * 3) & theKey & ":" \
                   && pArray[theKey] & cr after theText
         else
            put pArray[theKey] into tElement
            if the number of lines of tElement > 1 then
               put " ..." into tTrailer
            else
               put empty into tTrailer
            end if
            put spaces(pDimension * 3) & theKey & ":" \
                   && (line 1 of tElement) & tTrailer & cr after theText
         end if
      end if
   end repeat
   return theText
end displayArray

function spaces n
   -- returns a string of n spaces
   put "" into s
   repeat n
      put space after s
   end repeat
   return s
end spaces


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to