> 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:237770
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=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54