Re: ‘Super Sub’ multidimensional arrays
Sean Cole (Pi)
sean at pidigital.co.uk
Thu Mar 11 18:03:36 EST 2021
On to Array use for File System Indexing:
Take a simple FS structure:
c:/
.FileC
Folder1
File1.txt
Folder2
Size (aka Folder2_1)
File2.txt
File2_1.png
Folder3
Folder4
Archive.zip
File4.doc
Say we want to store in our indexing array the sizes, creation dates and
kind of every file, folder and volume.
If we ploughed in without thinking to much about it we might put File1.txt
in as: 'put tValue into
tTableA["c:/"]["Folder1"]["File1.txt"][tParameter]' with tParameter
being "Size", "Date" or "Kind". That seems ok.
But what about, then, size of Folder2? 'put tFldrSize into
tTableA["c:/"]["Folder2"]["Size"]' . What happens to the contents of a
folder 'named' "Size" once the parameter 'Size' gets written to in the
array? It writes over all of it.
So, maybe, a 'better', more manageable approach might be to have parameters
stored thusly: 'put tFldrSize into tTableA["c:/"]["Folder2","Size"]'
Then the File named "File2.txt" could be stored
as tTableA["c:/"]["Folder2"]["Size"]["File2.txt"] without fear
that ["c:/"]["Folder2"]["Size"] might be overwritten accidentally by a
parameter.
Likewise, "Folder3" can readily be stored as ["Folder3","Kind"]="Folder"
and "Archive.zip" could have a kind set as "Zip", and could then be scanned
even later for its contents with them being added to the sub-structure of
the array.
So, using {curly brackets} to denote optional parameters, the syntax for
this array could be thought of as:
put tValue into tMyArrayA [tItemName {, tParameterName} ]
put tValue into tMyArrayA [tItemName ] { [tItemName] ... [tItemName
{, tParameterName} ] }
put tFolderA into tMyArrayA [tItemName ] { ... [tItemName ] }
I hope that all makes sense.
Sean
More information about the use-livecode
mailing list