Quoting jp / jeffpritchard.com, on Sat, May 13, 2006 at 11:06:27AM +0900: > the best idea I was able to come up with was to read the > whole file into an array using File#readlines. After that, I used > Array#for_each_with_index to zip through the array looking for the end > of the block (being careful to watch out for inner blocks as well). > whole bloody file into memory first. Is there something obvious that I > could have done instead that would allow me to look at the file the same > way but leave it on disk instead of in memory? IO mixes in Enumerable, so it has a #each_with_index method that would use IO buffering: ensemble:~ % ruby -e '$stdin.each_with_index {|i,l| p i; p l; }' < /etc/passwd "nobody:*:-2:-2:Unprivileged User:/dev/null:/dev/null\n" 0 "root:*:0:0:System Administrator:/var/root:/bin/tcsh\n" 1 "daemon:*:1:1:System Services:/var/root:/dev/null\n" 2 Cheers, Sam