HI, I have just picked up RR and want as an intial exercise to be able to Open a CSV file, read each record until the end; process each record ; write out new records based on input info to an output file and then close both.
The file records are basic stock info with Open, High, Low, Close prices, ticker symbol and date and time. I need to be able to compare dates and recognise earlier or later dates and times. Need to be able to manipulate the numbers in the Open High Low etc. Of course being a CSV file all the data is text, but I need the numbers and dates to do the processing.
the logic of what I want to do is very easy to specify but figuring out in RR how to do this is not.
can anyone give any pointers to specific RR facilities and syntax to do this. RR's documentation doesn't seem very helpful on this as yet (although I may eventually discover different as I dig around).
Separate but slightly related question: Does RR have any concept of User Defined Types, or record structures or similar? I would like to treat each line of the incoming file as a record (or struct in c or equivalent) but cannot see anything in RR that conforms to this.
TIA
Neil
Processing Comma separated files stock info
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
What I do in this situation is use the url command for file i/o to read and write the whole file at one time:
Then within those file commands I process each line:
set the itemDelimiter to tab or comma, as appropriate
...and no, there isn't anything like a c struct, although rev does have hashes or associative arrays, and I use them similarly. You can't read or write a block at a time like you can with structs, but you can say
and then tData[tTickerSymbol] has all the pertinent data for a given stock, i.e.,
Code: Select all
put url ("file:" & tFileSpec) into tInputData
put tOutputData into url ("file:" & tFileSpec)
Code: Select all
repeat for each line tLine in tInputData
-- assuming the date is the sixth item in the line
if item 6 of tLine < tTargetDate then
-- do something
end if
put tLine & cr after tOutputData
end repeat
...and no, there isn't anything like a c struct, although rev does have hashes or associative arrays, and I use them similarly. You can't read or write a block at a time like you can with structs, but you can say
Code: Select all
put item 5 of tLine into tTickerSymbol
put item 1 of tLine into tData[tTickerSymbol]["Open"]
put item 2 of tLine into tData[tTickerSymbol]["High"]
put item 3 of tLine into tData[tTickerSymbol]["Low"]
put item 4 of tLine into tData[tTickerSymbol]["Close"]
Code: Select all
put tData["MSFT"]["Close"] into tMSFTClosingPrice
And I'd also point you to the scripting conference proceedings at http://support.runrev.com/scriptingconferences/ (I really wish runrev had a link to these on their support pages), in particular Ken Ray's discussion of "How To Work With Files".
Thanks for both items, very helpful.mwieder wrote:And I'd also point you to the scripting conference proceedings at http://support.runrev.com/scriptingconferences/ (I really wish runrev had a link to these on their support pages), in particular Ken Ray's discussion of "How To Work With Files".
