[#35446] [Ruby 1.9 - Bug #4477][Open] Kernel:exec and backtick (`) don't work for certain system commands — Joachim Wuttke <j.wuttke@...>

10 messages 2011/03/07

[#35476] [Ruby 1.9 - Bug #4489][Open] [PATCH] Encodings with /-(unix|dos|mac)\Z/ — "James M. Lawrence" <quixoticsycophant@...>

20 messages 2011/03/10

[#35552] [Ruby 1.9 - Feature #4523][Open] Kernel#require to return the path of the loaded file — Alex Young <alex@...>

14 messages 2011/03/24

[#35565] [Ruby 1.9 - Feature #4531][Open] [PATCH 0/7] use poll() instead of select() in certain cases — Eric Wong <normalperson@...>

33 messages 2011/03/28

[#35566] [Ruby 1.9 - Feature #4532][Open] [PATCH] add IO#pread and IO#pwrite methods — Eric Wong <normalperson@...>

12 messages 2011/03/28

[#35586] [Ruby 1.9 - Feature #4538][Open] [PATCH (cleanup)] avoid unnecessary select() calls before doing I/O — Eric Wong <normalperson@...>

9 messages 2011/03/29

[ruby-core:35534] [Ruby 1.9 - Bug #4515][Open] File.each_line read all lines of file as one line

From: Yen-Nan Lin <redmine@...>
Date: 2011-03-21 13:05:34 UTC
List: ruby-core #35534
Issue #4515 has been reported by Yen-Nan Lin.

----------------------------------------
Bug #4515: File.each_line read all lines of file as one line
http://redmine.ruby-lang.org/issues/4515

Author: Yen-Nan Lin
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [i386-darwin9.8.0]


I access a tab-delimited text file from Excel, the text file is 5 lines in my editors (TextEdit, TextWrangler).

However, when I use File.each_line to read it, this method only iterate once and combine 5 lines to 1 line.

I expect my code to puts count = 5, but it print 1.

Below is my code, the test2.txt file is in attachment if you need. 

----------------------------------------------------

filePath = "test2.txt"

data = Array.new

File.open(filePath, 'r') do |f|
	count = 0
	f.each_line do |line|
		data << line.split.map { |entry| entry.to_i }
		count += 1
	end
	puts count	
end

----------------------------------------------------------

I find a solution in http://railsforum.com/viewtopic.php?id=15582

But I think this bug should be solved.

Thank you very much!!

Yen-Nan Lin


-- 
http://redmine.ruby-lang.org

In This Thread

Prev Next