>How would some of you take this text file and parse it into a structure?
I might do something like the code below.
Specific points in comparison to other response:
- Uses cfsavecontent not a multi-line cfset
- Strips off unwanted stuff before looping, instead of cfif inside loop.
- Does Positions[Name] instead of Positions["#Name#"]
But also has other simplifications.
(Ideally I'd use reMatch instead of reReplace, but this way will run on CF7.)
---
<cfsavecontent variable="InputText">options (direct=true, errors=999999)
load data
into table raw_i
append
(record_id position(1:1) CHAR,
process_mt position(2:3) CHAR,
process_yr position(4:5) CHAR,
*snip*
summary_cd position(121:124) CHAR,
file_date position(125:144) DATE "DD-MON-YYYY HH24:MI:SS",
file_name position(*) CHAR TERMINATED BY X'0A'</cfsavecontent>
<cfset InputText = ListRest(ListRest(InputText,'('),'(') />
<cfset Positions = StructNew()>
<cfloop index="CurRow" list="#InputText#" delimiters="#Chr(10)#">
<cfset Name = ListFirst(CurRow,' ')/>
<cfset Pos = rereplace(CurRow,'^.*position\(([^)]+)\).*$','\1')/>
<cfset Positions[Name] = StructNew()/>
<cfset Positions[Name].Start = ListFirst(Pos,':')/>
<cfset Positions[Name].End = ListLast(Pos,':')/>
</cfloop>
---
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315899
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4