in reply to searching for a keyword with context window

I'm guessing your kwicionary is rather constant. If so, you can build an index (word => file position) outside of the CGI script, and store it to disk. There must be algorithms out there to build index files which don't need to be completely loaded into memory, but I'm not familiar with them. On second thought, a database would be perfect to store the index.

The CGI script could

  1. Locate the position of the word using the index file/table.
  2. Open the dictionary file.
  3. Seek to the position found in the index file.
  4. Read past the word.
  5. Read five words. Those are your Next Five Words.
  6. Reopen the dictionary file with File::ReadBackwards.
  7. Seek to the position found in the index file.
  8. Read five words. Those are your Previous Five Words.
  • Comment on Re: searching for a keyword with context window