[thelist] What is the ColdFusion equivalent to eval()?

Joshua Olson joshua at alphashop.net
Tue Apr 24 00:40:26 CDT 2001


Jon,

> <cfloop index="i" from="1" to="#ArrayLen("my_arr")#">
> <cfset order_#id# = ListToArray("my_arr[#i#]","-")>
> </cfloop>

Should be:

<cfloop index="i" from="1" to="#ArrayLen(my_arr)#">
  <cfset t = SetVariable("order_#id#", ListToArray(my_arr[i],"-"))>
</cfloop>

That is, assuming you really intend to have the variables order_1, order_2,
order_3 really contain arrays.

[To answer your question, ColdFusion does have a function called Evaluate.
Check out the documentation for it.  There is another related function
called DE (Delayed Evaluate) which you should keep in mind as well.]

More importantly, however, is the question about the #i#.

> <cfloop index="i" from="1" to="#ArrayLen("my_arr")#">
> <cfset order_#id# = ListToArray("my_arr[#i#]","-")>
> </cfloop>
>
> Also, is the #i# used in the ListToArray function
> correct? [sic]

ListToArray("my_arr[#i#]","-")

is correct syntax, but probably won't give you the results you expect.  What
this is telling ColdFusion is that the list you want to convert to an array
is literally the string "my_arr[1]", using the dash as the delimiter.
(assuming that i = 1)  In this case you would have a single element in the
list.  Probably not what you want.  To fix it, simply drop the quotes,
leaving:

ListToArray(my_arr[#i#],"-")

or better yet (if you are so inclined:

ListToArray(my_arr[i],"-")

To confuse the issue, these *would* work:

ListToArray("#my_arr[#i#]#","-")
ListToArray("#my_arr[i]#","-")

because ColdFusion would evaluate what's inside the hashes.  Phew.

There's a lot of idiosyncrasies involved, but there is a method to the
madness.  I don't feel like going into a long discussion about this now, but
I may if asked tomorrow.

Hope this helps,
-joshua





More information about the thelist mailing list