Shorthand ColdFusion Structs and Reserved Keywords

Posted: August 5, 2009 in ColdFusion

Today I attempted to create a struct in ColdFusion 8 via shorthand using the syntax:

<cfscript>
struct = {key1=val1,key2=val2};
</cfscript>

My case was creating a state list with abbreviation for keys and the state name as the value. However I have determined that not all key names can be used. If it is a reserved ColdFusion word, it may not work. For example “IN” and “OR”.

What I want:

<cfscript>
var strStates = {IN="Indiana",OR="Oregon",UT="Utah"};
</cfscript>

But that leaves me with an “Invalid CFML construct found…”.

So as a workaround I did this:

<cfscript>
var strStates = {UT="Utah"};
strStates["IN"] = "Indiana";
strStates["OR"] = "Oregon";
</cfscript>

So much for shorthand. Has anyone found a better solution for this?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s