Ruby CSV in Array
Posted
by
mattrock
on Stack Overflow
See other posts from Stack Overflow
or by mattrock
Published on 2014-06-13T12:04:17Z
Indexed on
2014/06/13
15:25 UTC
Read the original article
Hit count: 209
I read a CSV file. This file looks like this
1.00 cm; 2.00cm ; 3.00 cm; ... ; 100 cm
2.00 cm; 4.00 cm; 6.00 cm; ... ; 100 cm
4.00 cm; 8.00 cm; 12.00 cm; ... ; 100cm
8.00 cm; 16.00 cm; 24.00 cm; ... ; 100cm
I have already written the following code
CSV.foreach("/Users/testUser/Entwicklung/coverrechner/CoverPaperDE.csv", col_sep: ';') do |row|
puts row[0]
end
This produces the following output:
1.00 cm
2.00 cm
4.00 cm
8.00 cm
Example: My matrix is constructed
1.1 1.2 1.3 1.4
2.1 2.2 2.3 2.4
3.1 3.2 3.3 3.4
4.1 4.2 4.3 4.4
I want the following output
1.1 2.1 3.1 4.1 1.2 2.2 3.2 4.2 ... 4.4
How does it work?
© Stack Overflow or respective owner