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:

struct = {key1=val1,key2=val2};

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:

var strStates = {IN="Indiana",OR="Oregon",UT="Utah"};

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

So as a workaround I did this:

var strStates = {UT="Utah"};
strStates["IN"] = "Indiana";
strStates["OR"] = "Oregon";

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


Leave a Reply

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

You are commenting using your 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