"Mathieu Bouchard" <matju / sympatico.ca> wrote in message news:Pine.LNX.3.96.1010325123327.19397B-100000 / relayer... > On Sun, 25 Mar 2001, Daniel Berger wrote: > > Ah, crud - I forgot to mention that I *do not* want to read the entire file > > into memory, which the readlines method appears to do (unless I'm mistaken). > > I also would like to avoid tricks like creating temporary files. > > tell me whether this works for you: > > class IO > def reverse_each(&proc) > seek(0,SEEK_END) > i = tell > j = nil > buf = "" > loop do > k = buf.rindex(10,-2) > if k then > proc.call buf.slice!(k+1..-1) > else > if i==0 then proc.call(buf); return self; end > j,i = i,[0,i-4096].max > seek(i,SEEK_SET) > buf = read(j-i) + buf > end > end > end > end > > f = File.open("/home/matju/rsa_edit.htm","r") > f.reverse_each {|x| print x } > Worked like a charm. I don't know ruby well enough yet to completely understand this code (the codeblock & proc.call are throwing me at the moment) but I take it that you're reading in a max. of 4k per line. Is that correct? Thanks! Dan