Forum: Ruby Re: getting the next line with the iterator

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
87e9a89c53ccf984db792113471c2171?d=identicon&s=25 Kroeger, Simon (ext) (Guest)
on 2006-04-28 09:48
(Received via mailing list)
> 	while
> 		if =~ /regExp/
> 			3.times { list << }
> 		end
> 	end
> end
> puts list

Well, yes. In the general case I would agree.
In this case I think

list = []'toto.txt', 'rb') do |myFile|
  while line = myFile.gets do
    3.times {list << myFile.gets} if line =~ /regExp/
puts list

is totally sufficient.


This topic is locked and can not be replied to.