Friday 31 August 2012

Good things about Railo (#1) - CFLOOP

G'day, this is just a quick one.

In my last post I was discussing looping over arrays, and how Adobe messed-up their implementation of looping over an array with <cfloop> a bit (3321646).  Overnight, Gert from Railo added a comment, drawing my attention to Railo's handling of same.  And I gotta say I'm impressed.



Here's the business:

<cfprocessingdirective pageencoding="utf-8">
<cfset daysOfWeek = ["Rāhina","Rātū","Rāapa","Rāpare","Rāmere","Rāhoroi","Rātapu"]>
<cfloop array="#daysOfWeek#" index="index" item="day">
     <cfoutput>#index#: #day#<br /></cfoutput>
</cfloop>
<hr />

<cfset daysOfWeek = {monday="Rāhina", tuesday="Rātū", wednesday="Rāapa", thursday="Rāpare", friday="Rāmere", saturday="Rāhoroi", sunday="Rātapu"}>
<cfloop collection="#daysOfWeek#" index="index" item="day">
     <cfoutput>#index#: #day#<br /></cfoutput>
</cfloop>
<hr />

<cfset daysOfWeek = "Rāhina,Rātū,Rāapa,Rāpare,Rāmere,Rāhoroi,Rātapu">
<cfloop list="#daysOfWeek#" index="index" item="day">
     <cfoutput>#index#: #day#<br /></cfoutput>
</cfloop>
<hr />

And the output:

1: Rāhina
2: Rātū
3: Rāapa
4: Rāpare
5: Rāmere
6: Rāhoroi
7: Rātapu
wednesday: Rāapa
thursday: Rāpare
monday: Rāhina
sunday: Rātapu
saturday: Rāhoroi
friday: Rāmere
tuesday: Rātū
1: Rāhina
2: Rātū
3: Rāapa
4: Rāpare
5: Rāmere
6: Rāhoroi
7: Rātapu

How good is that?

Nice one, Railo.  I'll update that ticket I raised with Adobe to suggest Railo's syntax ("item" rather than my suggestion "element") instead.

Time to play catch-up, Adobe...

--
Adam


PS: this a bit quite funny: