Question
Array of structures - two ways to approach - which is better?
Folks - I've been trying to create an array of structures,
but I bumped into problem that lead me to an example that is
completely different. I'm trying to figure out which is valid. In
general, it comes down to this:
(1) myStructure .firstName
vs
(2) myStructure.firstName
The problem with the first is that I can't find a way to discover the size of the array, which leads me to suspect this is not a valid method. The problem with the second is that you must redefine the structure for EACH array element, which seems like it would add a lot of overhead.
Any advice? Sample code attached.
Thanks!
************* Sample (1) **************
<CFSET sCust=StructNew()>
<CFSET vCustCount = #rsMailAuth.recordcount#>
<CFSET i = 0>
<CFOUTPUT QUERY="rsMailAuth">
<CFSET i = i+1>
<CFSET sCust.userId = #rsMailAuth.userId#>
<CFSET sCust.validEmailSource = #rsMailAuth.validTcEmails#>
<CFSET sCust.authKeyword = #rsMailAuth.tcEmailKeyword#>
<CFSET sCust.authKeywordLoc = #rsMailAuth.tcEmailKeywordLoc#>
</CFOUTPUT>
************* Sample (2) **************
<cfset strTest = arrayNew(1) >
<cfset strTest[1] = structNew() >
<CFLOOP INDEX = "i" FROM="1" TO="5" >
<cfset strTest = structNew() >
<cfset strTest.id = i>
<cfset strTest .name = "#i#name@mail.com">
</CFLOOP>
<cfoutput>#arrayLen(strTest)#</cfoutput>
(1) myStructure .firstName
vs
(2) myStructure.firstName
The problem with the first is that I can't find a way to discover the size of the array, which leads me to suspect this is not a valid method. The problem with the second is that you must redefine the structure for EACH array element, which seems like it would add a lot of overhead.
Any advice? Sample code attached.
Thanks!
************* Sample (1) **************
<CFSET sCust=StructNew()>
<CFSET vCustCount = #rsMailAuth.recordcount#>
<CFSET i = 0>
<CFOUTPUT QUERY="rsMailAuth">
<CFSET i = i+1>
<CFSET sCust.userId = #rsMailAuth.userId#>
<CFSET sCust.validEmailSource = #rsMailAuth.validTcEmails#>
<CFSET sCust.authKeyword = #rsMailAuth.tcEmailKeyword#>
<CFSET sCust.authKeywordLoc = #rsMailAuth.tcEmailKeywordLoc#>
</CFOUTPUT>
************* Sample (2) **************
<cfset strTest = arrayNew(1) >
<cfset strTest[1] = structNew() >
<CFLOOP INDEX = "i" FROM="1" TO="5" >
<cfset strTest = structNew() >
<cfset strTest.id = i>
<cfset strTest .name = "#i#name@mail.com">
</CFLOOP>
<cfoutput>#arrayLen(strTest)#</cfoutput>
