From: "Peña, Botp" Date: 2008-03-07T11:34:54+09:00 Subject: Re: IO#Foreach -- Max line length On Behalf Of Tristin Davis: # But by the time you actually get count, isn't the line # already read in # memory. So if the line is 7 gigabytes, it'll probably crash # the system. read will accept arg on how many bytes to read. so how about, irb(main):040:0> File.open "test.rb" do |f| f.read end => "a=(1..2)\n\na\nputs a\n\nputs a.each{|x| puts x}" irb(main):041:0> File.open "test.rb" do |f| f.read 2 end => "a=" irb(main):042:0> File.open "test.rb" do |f| f.read 2; f.read 2 end => "(1" irb(main):043:0> File.open "test.rb" do |f| while x=f.read(2); p x; end; end "a=" "(1" ".." "2)" "\n\n" "a\n" "pu" "ts" " a" "\n\n" "pu" "ts" " a" ".e" "ac" "h{" "|x" "| " "pu" "ts" " x" "}" => nil kind regards -botp