> I think Allaire need to do something about this feature, I've been writing
> backend scripts which take mainframes output into PC. CFFile just doesn't
> work. Immagine the content of the mainframe output, the columns are
> delimited by fixed length, and some delimited by empty spaces....
>
> CFFile is too stupid to handle text file like such, therefore, I
> have to use
> PHP, and I highly recommend anyone need to deal with text file
> manipulation
> uses PHP.
The concept is right except it is better to dump it into CF array instead of
using PHP (assuming you are using the output in a CF context).
The array is much quicker than a list.
Lets face it. CF (at least this version) wasn't meant to do heavy
processing of plain text files, but it doesn't mean that it can't do it very
well.
Example below (watch the word wrap if you cut and paste):
------------------cut and paste this code-----------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<h3>Test CFFILE - Looping Over Lines</h3>
<cfset thisPath = ExpandPath("*.*")>
<cfset thisDirectory = GetDirectoryFromPath(thisPath)>
<!--- enter your filename here --->
<cfset file = "index.cfm">
<!--- only bit you need to change --->
<cftry>
<cffile action="READ" file="#thisDirectory##file#" variable="myfile">
<cfcatch type="Any">
<b>You have not specified a file in the correct directory. Please set
the file variable to an existing file.</b>
<cfabort>
</cfcatch>
</cftry>
<p>
I hope you can see that the loop code is the same in both instances except
for the fact
that the <b>ListToArray</b> is used to create an array in the first example
and the
simple <b>list format</b> is used (without an intermediate step) in the
other.
</p>
<p>
What (I hope) you will find is that using the array is much quicker.
</p>
<table border="1">
<tr>
<td>
<b>Using ListToArray()</b>
</td>
<td>
<b>Using Simple List Delimited by newlines</b>
</td>
</tr>
<!--- code ListToArray --->
<cfset a = GetTickCount()>
<cfset file1 = "">
<cfset myfile_array = ListToArray(myfile, "#Chr(10)##Chr(13)#")>
<cfloop from="1" to="#ArrayLen(myfile_array)#" index="i">
<cfset line = REReplace(myfile_array[i],"<","<", "all")>
<cfset line = REReplace(line,">",">", "all")>
<cfset file1 = file1 & line & "<br>">
</cfloop>
<cfset b = GetTickCount()>
<cfset c = b - a>
<!--- code List Loop --->
<cfset d = GetTickCount()>
<cfset file2 = "">
<cfloop from="1" to="#ListLen(myfile, '#Chr(10)##Chr(13)#')#" index="i">
<cfset line = REReplace(ListGetAt(myfile, i,
"#Chr(10)##Chr(13)#"),"<","<", "all")>
<cfset line = REReplace(line,">",">", "all")>
<cfset file2 = file2 & line & "<br>">
</cfloop>
<cfset e = GetTickCount()>
<cfset f = e - d>
<tr>
<td valign="top"><cfoutput>Time taken: #c# ms</cfoutput></td>
<td valign="top"><cfoutput>Time taken: #f# ms</cfoutput></td>
</tr>
<tr>
<cfoutput>
<td><font size="1">#file1#</font></td>
<td><font size="1">#file2#</font></td>
</cfoutput>
</tr>
</table>
</body>
</html>
------------------cut and paste this code-----------------
Enjoy!
Paul
------------------------------------------------------------------------------
To unsubscribe, send a message to [EMAIL PROTECTED] with
'unsubscribe' in the body or visit the list page at www.houseoffusion.com