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.


7stud -- wrote:
> Tristin Davis wrote:
>> I'm trying to emulate the new feature in 1.9 that allows you to specify
>> the maximum length of a line read in Ruby 1.8.6.  Can anyone help?
> 
> max = 3
> count = 0
> 
> IO.foreach('data.txt') do |line|
>   if count == max
>     break
>   else
>     count += 1
>   end
> 
>   puts line
> end

-- 
Posted via http://www.ruby-forum.com/.