Here's a scenario where ColdFusion is a pleasure to work with:
<cfquery name="get_all_products" dataSource="ODBC_DSN">
SELECT id,title FROM products
</cfquery>
<cfoutput query="get_all_products">
<option value="#id#">#title#</option>
</cfoutput>
The same thing in Perl
Here's a scenario where Perl cleans house. Let's say I have a Web form with multiple records with multiple input fields and so I name the fields with the naming convention fieldname _ ID# (i.e. title_1, caption_1
use CGI;
use DBI;
my $dbh = DBI->connect(
my $q = new CGI;
my @ids;
my $sth = $dbh->prepare( 'UPDATE products SET title=?,caption=? WHERE id=?' );
foreach ( grep(
my ( $id ) =
next if grep { $_ == $id }, @ids; # I forget
push @ids, $id;
$sth->execute( $q->param( "title_$id" ), $q->param( "caption_$id" ), $id );
}
But here's what my ColdFusion code looks like so far (*cringe*)
<cfset ids = ''>
<cfloop index = 'key' list = '#Form.FieldNames#'>
# Notice the line below. ColdFusion has some regular expression support
# but its regex functions do not return matches - just the position within
# the string. It has some match support, but if you use it, it returns
# an array of position markers where the matches took place - not the
# matches themselves. So I have to resort to replacing the non-digit
# characters out of the field name so I can deal with it.
# Oh, btw, this really isn't a valid comment - CF comments look like this:
<!--- This is a CF Comment --->
<cfset id_num = REReplaceNoCase( #key#, "[^0-9]", '', "ALL" )>
# Ok, notice ListFindNoCase()
# determined by the method name (yes, there's a ListFind() that is
# case-sensitive. Oh, btw, all variable names in ColdFusion are case-
# insensitive. So I could say ids, IDS or IdS in the
# line below and it wouldn't matter.
<cfif id_num GE 0 AND ListFindNoCase( ids, id_num ) IS 0 >
IDS: <cfdump var="#id_num#">
<cfset ids = ListAppend( ids, id_num )>
</cfif>
</cfloop>
<cfloop index = 'i' list = "#ids#">
<cfset sku_field = "Form.sku_" & #i#>
<cfset title_field = "Form.title_" & #i#>
<cfset caption_field = "Form.caption_" & #i#>
<cfset image_field = "Form.image_" & #i#>
<cfset pricing_field = "Form.pricing_" & #i#>
<cfset special_pricing_field = "Form.special_pricing_" & #i#>
<cfset sql = "UPDATE products SET sku='" & Evaluate(#sku_field#) & ",title='#title_field#',caption='#caption_field#',image='#image_field#',pricing
<cfdump var="#sql#">
<cfoutput><P>SQL: #sql#</P></cfoutput>
<!---
<cfquery datasource = 'ODBC_DSN' name = ''>
</cfquery>
--->
</cfloop>
Fun Fun!
Peace,
Jason
Look at CFSCRIPT (Score:2)
--
xoa
Re:Look at CFSCRIPT (Score:1)
Jason
Feeling your pain (Score:1)
My favorite little quirk so far is the lack of block specific variable scoping. For example variables created in cffunctions still have the same global scope as those created outside of functions.
You can get around this using CFscript's Var() operator to locally scope variables.
Re:Feeling your pain (Score:2)