I found this rather interesting.  If you want to create nested associative arrays in many languages you can easily embed one within another on the same line when declaring it.  Unfortunately, it appears this is not true of ColdFusion when using the { } bracket notation in CF8.

For example, lets say you want to create a struct that looks like this:

You might try the following:

?View Code COLDFUSION
1
<cfset uploadstr = {uploadid="#form.uploadid#", uploadinfo={tempname="#cffile.serverDirectory##cffile.serverFile#", maxsize="#cffile.fileSize#"}}>

Unfortunately, when attempting to compile the template, coldfusion raises an exception with the nested brackets.  You must define the inner structures first like this:

?View Code COLDFUSION
1
2
<cfset uploadinfostr = {tempname="#cffile.serverDirectory##cffile.serverFile#", maxsize="#cffile.fileSize#"}>
<cfset uploadstr = {uploadid="#form.uploadid#", uploadinfo=uploadinfostr}>
This entry was posted on Wednesday, August 15th, 2007 at 2:34 pm.
Categories: Uncategorized.

No Comments, Comment or Ping

Reply to “creating nested structures using { } brackets”