Isaac,

Thanks for the <script>, will have to play around with it.

I also found Structget(), but it doesn't like anything other than alpha and
numeric in the Keys.
Even using ['item 1'], Structget() throws an error or ['item-1'], has to be
['item1'].

Using  rereplace(key, '[^[:alpha:]]', "","all")  when I create the
structure, I can get Structget() to work.

It is a pain, because then everytime the structure is searched,the rereplace
needs to be done on the key.

But this is still faster than looping thru the structure to find a key(at
least on large Structures).

        FoundPath = StructKeyFind(MyStruct, rereplace(key, '[^[:alpha:]]',
"","all") )
        NewPath = 'MyStruct' & FoundPath[x].path
        FoundKey = StructGet(Newpath)

        #FoundKey.lastitem#

        can even:
          FoundKey[newitem] = StructNew()
          FoundKey[newitem].hours = hoursWorked

In my case here newitem would be a persons id.

Rodney


                        


-----Original Message-----
From: S. Isaac Dealey [mailto:[EMAIL PROTECTED] 
Sent: Friday, April 14, 2006 9:59 AM
To: CF-Talk
Subject: Re: StructFindKey Path and evaluate


> Hi all


> I have a structure I am using StructFindKey with.

> Which returns an array/Structure.

> One of keys returned is Path, which is a dot separated
> list of the path thru
> the structure to the key your looking for.

> Something like:  MyStruc.item1.item2.item3.item4 (find key Item4), 
> returns item1.item2.item3.item4

> I tried:  NewPath = 'MyStruc' & Path (with and without
> using evaluate)
> couldn't get it to work.
> I did get this to work:
>       did a replace to make path =
>       ['item1']['item2']['item3'['item4']
>       NewPath = 'MyStruc' & path

> <CFOUTPUT>#Evaluate(NewPath & '.lastitem')#</cfoutput>

> Is there anyway to get this to work with out using
> Evaluate?

> Hope I explained this well enough?

Yes, but in this case evaluate might actually be faster.

<cfscript>
temp = Mystruc;
aPath = listToArray(path);
arrayDeleteAt(aPath,1);
while (arrayLen(aPath)) {
        temp = temp[aPath[1]];
        arrayDeleteAt(aPath,1);
}
</cfscript>
<cfoutput>#temp.lastitem#</cfoutput>

You could encapsulate that into a function, which would make it less
efficient but gain you loads of maintainability (imo that's important).

I've used this strategy for getting nested values before, but not for the
sake of efficiency -- in my case I've done this when I didn't know what the
names of keys might be, so this allows the storage of keys that begin with
numbers or are for some other reason invalid variable names which would
produce an error with the isDefined() function. If you know that all your
structure keys begin with alpha characters, don't contain hyphens, etc. then
it is probably more mechanically efficient in this case to use the single
evaluate() than to use the loop and indeterminate number of array management
statements.

s. isaac dealey     434.293.6201
new epoch : isn't it time for a change?

add features without fixtures with
the onTap open source framework

http://www.fusiontap.com http://coldfusion.sys-con.com/author/4806Dealey.htm




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:237787
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54
  • RE: StructFindKey Path... Bruce, Rodney S C-E LCMC HQISEC/Signal Solutions

Reply via email to