Adobe COLDFUSION 9 Manual page 81

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
The following example shows the
<cfset myVar2="myVar">
<cfset myVar="27/9">
<cfoutput>
#myVar2#<br>
#myVar#<br>
#Evaluate("myVar2")#<br>
#Evaluate("myVar")#<br>
#Evaluate(myVar2)#<br>
#Evaluate(myVar)#<br>
</cfoutput>
Reviewing the code
The following table describes how ColdFusion processes this code:
Code
<cfset myVar2="myVar">
<cfset myVar="27/9">
<cfoutput>
#myVar2#<br/>
#myVar#<br/>
#Evaluate("myVar2")#<br>
#Evaluate("myVar")#<br>
#Evaluate(myVar2)#<br>
#Evaluate(myVar)#<br/>
</cfoutput>
As you can see, using dynamic expressions can result in substantial expression evaluation overhead, and the code can
be confusing. Therefore, you should avoid using dynamic expressions wherever a simpler technique, such as using
indexed arrays or structures can serve your purposes.
Avoiding the Evaluate function
Using the
function increases processing overhead, and in most cases it is not necessary. These examples
Evaluate
show some cases where you can consider using the
function and how it works with ColdFusion variable processing:
Evaluate
Description
Sets the two variables to the following strings:
myVar
27/9
Displays the values assigned to the variables, myVar and 27/9, respectively.
Passes the string "myvar2" (without the quotation marks) to the Evaluate function, which
does the following:
1 Evaluates it as the variable myVar2.
2 Returns the value of the myVar2 variable, the string "myvar" (without the quotation
marks).
Passes the string "myvar" (without the quotation marks) to the Evaluate function, which
does the following:
1
Evaluates it as the variable myVar.
2 Returns the value of the myVar variable, the string "27/9" (without the quotation marks).
Evaluates the variable myVar2 as the string "myVar" and passes the string (without the
quotation marks) to the Evaluate function. The rest of the processing is the same as in the
previous line.
Evaluates the variable myVar as the string "27/9" (without the quotation marks), and passes
it to the Evaluate function, which does the following:
1
Evaluates the string as the expression 27/9
2 Performs the division.
3 Returns the resulting value, 3
function:
Evaluate
Last updated 8/5/2010
76

Advertisement

Table of Contents
loading

Table of Contents