dealing w/ multidimensional arrays

Jan Schenkel janschenkel at yahoo.com
Mon Oct 14 08:20:00 EDT 2002


--- Alex Rice <alex at mindlube.com> wrote:
> 
> On Sunday, October 13, 2002, at 10:04  PM, David
> Vaughan wrote:
> 
> >
> > On Monday, Oct 14, 2002, at 13:29
> Australia/Sydney, Alex Rice wrote:
> >
> > Alex
> >
> >> "... having to scan all the keys and weed out the
> parts..."
> >
> > there is "filter", or were you not really saying
> what it says?
> 
> Filter will work for this particular problem, but I
> want to point out 
> it could be potentially dangerous and isn't really
> correct. Supposing 
> you have several keys in a multidimensional array
> 
> myArr[key1,key2,key3,key4,key5] -- 5 dimensions in
> this array
> put myArr into tArr
> filter tArr with "something" -- filter by a string
> we know occurs in 
> key1
> 
> But what if the string "something" occurs in
> key2,key3,key4 or key5? 
> Not really what I want. If filter accepted a regex
> and I could say
> 
> filter tArr with "^something" -- anchor to beginning
> of key
> 
> that would make me feel better.
> 

Hi Alex,

Actually, the 'filter' command works its way from left
to right, so suppose we have a multi-dimensional array
with the following keys:
firstKey1,secondKey1,thirdKey1
firstKey1,secondKey1,thirdKey2
firstKey1,secondKey2,thirdKey1
firstKey1,secondKey2,thirdKey2
firstKey1,secondKey3,thirdKey1
firstKey1,secondKey3,thirdKey2
firstKey2,secondKey1,thirdKey1
firstKey2,secondKey1,thirdKey2
firstKey2,secondKey2,thirdKey1
firstKey2,secondKey2,thirdKey2
firstKey2,secondKey3,thirdKey1
firstKey2,secondKey3,thirdKey2

You can easily get all the data you want:
  put the keys of myArray into myKeys
  filter myKeys with "firstKey1,*"

At this point myKeys will be filtered down to:
firstKey1, secondKey1, thirdKey1
firstKey1, secondKey1, thirdKey2
firstKey1, secondKey2, thirdKey1
firstKey1, secondKey2, thirdKey2
firstKey1, secondKey3, thirdKey1
firstKey1, secondKey3, thirdKey2

So if you only want the data in 
  myArray[firstKey1,secondKey3]
You would
  put the keys of myArray into myKeys
  filter myKeys with "firstKey1,secondKey3,*"

And then of course you could build a new array using
  repeat for each line tSourceKey of myKeys
    put tSourceKey into tTargetKey
    delete item 1 to 2 of tTargetKey
    put myArray[tSourceKey] into \
      myNewArray[tTargetKey]
  end repeat
Or something similar to this construction.

Hope this helped,

Jan Schenkel.

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)

__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com



More information about the use-livecode mailing list