From: Jon Handler Date: 2007-12-08T07:09:49+09:00 Subject: Re: Question about iterators and reading a file Adam Shelly wrote: > On 12/7/07, Jon Handler wrote: >> I need to advance to the next line of the file within the loop but I >> can't for the life of me figure out how to do that. This can't be hard, >> but it's defeated me so far! >> > That's the cool thing about 'each' - you don't have to do anything > else. The code inside the do-end block will be called for each line, > with l set to that line. Try adding 'puts strln' in place of "Now > what". That will print the whole file. Then replace the puts with > whatever processing you want to do on each line. > > -Adam Hi. Thanks for responding! I wasn't clear about this... my problem is that I want to do something different depending on which line I'm looking at. Here's some psuedo code: for the whole file read one line with the identifying string read one line with the count of items for each item read one line with the data end save the whole record as an object indexed by the identifying string end The problem is that this is not a line-oriented set of data. So I have to have some kind of nested loop that advances the line counter. Or, there has to be some record-oriented I/O that lets me process the file as a set of records. Surely there's some cool, ruby way to do this?!?? Thanks again, Jon -- Posted via http://www.ruby-forum.com/.