From: Carl Lerche Date: 2007-02-22T09:37:51+09:00 Subject: Re: Parsing a file with look ahead The first thing I can think of is do file.each_line and store that line in a previous_line variable at the end of the proc. Then you have access to the line that was read before hand and the current one. On 2/21/07, S. Robert James wrote: > I need to parse a file line by line, and output the results line by > line (too big to fit into memory). So far, simple enough: > file.each_line. > > However, the parser needs the ability to peek ahead to the next line, > in order to parse this line. What's the right way to do this? Again, > I really don't want to try to slurp the whole file into memory and > split on newlines. > > Here's an example: > Line1: Hi > Line2: How > Line3: Are > Line4: you? > > I'd like to: > parse('Hi', 'How') > parse('How', 'Are') > parse('Are', 'you?') > parse('you?', false) > # hey, this is practically a unit test! > > Any ideas? > > > -- EPA Rating: 3000 Lines of Code / Gallon (of coffee)