Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / BUG: File seek not working

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. BUG: File seek not working
#10437
Posted by: chucksim 2007-05-03 21:45:24 Last edited by: Jeff Glatt 2007-06-18 16:01:06 (Total edited 1 time)
I have a very large file (90810 lines of 33 chars). I am trying to find the quickest way to read a certain line in the file so I thought I would seek from the end of the file if the line I wanted was over half way down. So I tried the following and it does not seem to work. It seems that trying to seek from the end of the file using READ LINE just sets the pointer to the number of lines specified from the top of the file. If I use READ CHAR it does. (I have to multiply the line number I want by 33 of course.)

Is <xxx READ LINE not an option?



fn='C:\Net\TABLEDATA.TXT'

start = 66700 /* The line I want */

max = 90817  /* Number of lines in the file */

mid = 90817 / 2  /* The midway point */

if start>mid then do
  start = max-start 
  offset = STREAM(fn, 'C', 'SEEK <'||start 'READ LINE')
end
else do
  offset = STREAM(fn, 'C', 'SEEK '||start 'READ LINE')
end

/* Check for an error */
IF DATATYPE(offset) \== "NUM" THEN SAY "There was an error seeking."

say offset

say linein(fn)
Chuck Simmons
Message2. Example script and file
#10447
Posted by: chucksim 2007-05-04 01:53:48
In the attached example, the say returns 1 indicating start of file
test.txta.rex
Chuck Simmons
Message3.
#10453
Posted by: Jeff Glatt 2007-05-04 22:10:04
Ok, that is a bug. Not sure when exactly I can get to fix it. But I'll mention a couple things:

1) If your lines are always a fixed length, then it is a lot faster to use a CHAR seek (and multiply by the length of the line. Don't forget to add 2 chars to the line length to account for the linefeed and newline chars at the end of each line).

2) Reginald already internally tries to optimizes line seeking, so you may not need to do that yourself.
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Mon 2022-12-5  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0