Page 1 of 1

Read file line for line?

Posted: Tue Sep 08, 2009 6:53 pm
by Garrett
I'm missing something here I'm sure. I'm trying to read a file line for line, but can't figure out how to tell Rev to move to the next line in the file.

Code: Select all

   put "...Downloads\enwiki-20090902-pages-articles.xml\enwiki-20090902-pages-articles.xml" into varFileToRead
   open file varFileToRead for read
   put 1 into varCounter
   put "filler" into varLineData
   --repeat until varLineData is empty
   read from file varFileToRead for 1 line
   put it into varLineData
   --end repeat
   close file varFileToRead
I'm using "read from file varFileToRead for 1 line" but see no way to tell Rev what line to read, unless it's not possible to use "line" in this manner, I did notice that it was shown as an example for "stdin" and not "file". If not possible, then I know I'll have to play a bit of a guessing game at using character counting to do this.

Any suggestions/help appreciated.

Thanks,
~Garrett

Posted: Tue Sep 08, 2009 8:09 pm
by Janschenkel
When you use

Code: Select all

read from file theFilePath for 1 line
the engine reads until it finds the first linefeed. You have to keep track of where you're at; even though there's a seek command to jump to a specific spot in the file or some relative distance from where you're at, there's no seekPosition function to tell you where you currently are.

Best of luck,

Jan Schenkel.

Posted: Tue Sep 08, 2009 9:06 pm
by Garrett
Ok, so I could do something like this then:

Code: Select all

seek varLineCounter in file varFileToRead
Basically, increment the "varLineCounter" myself so I know which line I'm on.

Sweet! That's what I needed, but of course, was looking for the wrong keyword in the docs....

Thanks again Jan! :D

Posted: Wed Sep 09, 2009 5:51 am
by Janschenkel
The seek command doesn't think in terms of lines, but in bytes/characters. Also bear in mind that read ... for 1 line may result in your slurping up the entire file, if the file doesn't contain linefeeds (as can be the case with XML files).

Jan Schenkel.