i am sorry, it may be too early and i may not have had enough coffee yet, but...
[q] toadd -- elements from list2 to be added to list1 todelete -- elements from list1 to be deleted (those that are not present in list2) [/q] looks to me like a long way around a simple <cfset list1 = list2>... :) you are basically making your list1 looks exactly like list2: deleting elements from it that are not in list2 and adding missing elements that are in list2... maybe after another cup of coffee i will see it differently... Azadi Saryev Sabai-dee.com http://www.sabai-dee.com/ Brian Dumbledore wrote: > I didn't want to extend the years old discussion on this thread, > http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:19468 > > I was looking for a custom tag which given two lists list1,list2 will give me > back a struct with two lists 'toadd' and 'todelete'. > > toadd -- elements from list2 to be added to list1 > todelete -- elements from list1 to be deleted (those that are not present in > list2) > > I wrote two versions, one based on lists and the other based on struct, in > all cases (even smaller sizes), struct version outperforms list version. > > Anyone care to comment? Both versions given below: > > STRUCT VERSION: > <!--- usage > <cf_listcompare list1="#list1#" list2="#list2#" returnvariable="abc" > delimiter=","> > ---> > <cfparam name="attributes.list1" default="" type="string"> > <cfparam name="attributes.list2" default="" type="string"> > <cfparam name="attributes.delimiter" default=","> > <cfparam name="attributes.returnvariable" type="variablename" > default="result"> > <cfset caller[attributes.returnvariable]=structnew()> > <cfset struct1 = structnew()> > <cfset struct2 = structnew()> > <cfloop list="#attributes.list1#" index="idx" > delimiters="#attributes.delimiter#"> > <cfset structinsert(struct1,"#idx#","","yes")> > </cfloop> > <cfset list1=structkeylist(struct1,"#attributes.delimiter#")> > > <cfloop list="#attributes.list2#" index="idx" > delimiters="#attributes.delimiter#"> > <cfset structinsert(struct2,"#idx#","","yes")> > </cfloop> > <cfset list2=structkeylist(struct2,"#attributes.delimiter#")> > > <cfif attributes.list1 neq "" or attributes.list2 neq ""> > <cfset toadd = structnew()> > <cfset todelete = structnew()> > <cfloop list="#list2#" index="idx" delimiters="#attributes.delimiter#"> > <cfif not structkeyexists(struct1,"#idx#")> > <cfset structinsert(toadd,"#idx#","")> > </cfif> > </cfloop> > <cfloop list="#list1#" index="idx" delimiters="#attributes.delimiter#"> > <cfif not structkeyexists(struct2,"#idx#")> > <cfset structinsert(todelete,"#idx#","")> > </cfif> > </cfloop> > <cfset > structinsert(caller[attributes.returnvariable],"toadd","#structkeylist(toadd,attributes.delimiter)#")> > <cfset > structinsert(caller[attributes.returnvariable],"todelete","#structkeylist(todelete,attributes.delimiter)#")> > </cfif> > > LIST VERSION: > > <cfparam name="attributes.list1" default="" type="string"> > <cfparam name="attributes.list2" default="" type="string"> > <cfparam name="attributes.delimiter" default=","> > <cfparam name="attributes.returnvariable" type="variablename" > default="result"> > <cfset caller[attributes.returnvariable]=structnew()> > <cfif attributes.list1 neq "" or attributes.list2 neq ""> > <cfset toadd = ""> > <cfset todelete = ""> > <cfloop list="#attributes.list2#" index="idx" > delimiters="#attributes.delimiter#"> > <cfif not > listfind(attributes.list1,idx,"#attributes.delimiter#") and not > listfind(toadd,idx,"#attributes.delimiter#")> > <cfset toadd = > listappend(toadd,idx,"#attributes.delimiter#")> > </cfif> > </cfloop> > <cfloop list="#attributes.list1#" index="idx" > delimiters="#attributes.delimiter#"> > <cfif not > listfind(attributes.list2,idx,"#attributes.delimiter#") and not > listfind(todelete,idx,"#attributes.delimiter#")> > <cfset todelete = > listappend(todelete,idx,"#attributes.delimiter#")> > </cfif> > </cfloop> > <cfset > structinsert(caller[attributes.returnvariable],"toadd","#toadd#")> > <cfset > structinsert(caller[attributes.returnvariable],"todelete","#todelete#")> > </cfif> > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:316004 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

