# Matrix problems (again!)

**URL:** https://rubytalk.org/t/matrix-problems-again/41236
**Category:** ruby-talk
**Created:** [8 October 2007 11:35 UTC](https://rubytalk.org/t/matrix-problems-again/41236 "2007-10-08T11:35:43Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![John\_Nott](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@John\_Nott](https://rubytalk.org/u/John_Nott)
#### Post date: [8 October 2007 11:35 UTC](https://rubytalk.org/t/matrix-problems-again/41236/1 "2007-10-08T11:35:43Z")

</div>

Hi everyone,  
As a complete new comer to Ruby. I have written this little piece of simple code but I have no idea why it only half works. It creates the matrix as I want it to but instead of populating it using the file as pointed to in file path, it fills it up with empty data!?

If anyone has any tips on where I may be going wrong I would really really appreciate it! I have remmed the code as best as I can throughout.

print "Importing Planning Sheet: 2004\_extrap\_Planning\_Data\n"

filepath = 'Q:\\TECH2006\\DBA\\02\_LU\\Final TAGM 2007 (working)\\TAGM\_666\_Current\_FROM G\_DRIVE\\2004\\2004\_extrap\_Planning\_Data.csv' #the file that contains teh data that i would like to put into the matrix

file = File.new(filepath, 'r') # define new file as filepath

mat1 = OtMatrix.new(649,19) # define new omni trans matrix 649 rows, 19 columns

fields = Array.new # define fields as a new array to hold data

r = 1 # matrix row r = first row  
n = 0 # n (fields) = 0  
c = 1 # matric column 1 = first column

while ( !file.eof )  
line = file.gets  
line.each(',') { |this\_record|  
&nbsp;&nbsp;fields \<\< this\_record.chomp(",").strip() # read to the end of the file into 'fields', split into lines and chomp out the delimiter  
&nbsp;&nbsp;mat1[r,c] = fields[r,c] # the rows and columns in the matrix = rows and columns in fields  
&nbsp;&nbsp;c=c+1  
&nbsp;&nbsp;n=n+1  
if c \> 19 then # loops through each row/column. At the end of each line where c=19, reset loop onto next row with col = 1  
c = 1  
end  
&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;  
end

print mat1

Thanks very much in advance!

> **···**
>
> #####################################################################################  
> This e-mail message has been scanned for Viruses and Content and cleared  
> by MailMarshal  
> #####################################################################################

---

<div class="post-metadata">

### Author: ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)
#### Post date: [8 October 2007 13:45 UTC](https://rubytalk.org/t/matrix-problems-again/41236/2 "2007-10-08T13:45:42Z")

</div>

John Nott wrote:

> 

This code

file = File.new("data.txt")  
fields =

while (!file.eof)  
&nbsp;&nbsp;line = file.gets  
&nbsp;&nbsp;line.each(',') do |this\_field|  
&nbsp;&nbsp;&nbsp;&nbsp;fields \<\< this\_field.chomp(",").strip()  
&nbsp;&nbsp;end  
end

p fields

with this file:

data.txt:  
10, 20, 30  
40, 50, 60

produces this array:

--\>["10", "20", "30", "40", "50", "60"]

(note that they are strings)

But that is poorly written code; I can see that you copied it off the OT  
website. Instead, you can write something like this:

results =

File.open("data.txt") do |file|  
&nbsp;&nbsp;file.each\_line(',') do |field|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results \<\< field.to\_i  
&nbsp;&nbsp;end  
end

p results  
--\>[10, 20, 30, 50, 60]

But then, it's not clear why you even need a results array. Instead,  
why not just insert each field straight into your matrix?

Also, in this code:

r = 1  
n = 0  
c = 1

line.each(',') { |this\_record|  
fields \<\< this\_record.chomp(",").strip()  
&nbsp;&nbsp;mat1[r,c] = fields[r,c]  
&nbsp;&nbsp;c=c+1  
&nbsp;&nbsp;n=n+1

1) the variable this\_record will actually be assigned a string like '3,'  
so it's not a record--it's one field.

2) The value for r never changes.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)
#### Post date: [8 October 2007 14:02 UTC](https://rubytalk.org/t/matrix-problems-again/41236/3 "2007-10-08T14:02:07Z")

</div>

7stud -- wrote:

> But that is poorly written code; I can see that you copied it off the OT  
> website. Instead, you can write something like this:
> 
> results =
> 
> File.open("data.txt") do |file|  
> &nbsp;&nbsp;file.each\_line(',') do |field|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results \<\< field.to\_i  
> &nbsp;&nbsp;end  
> end
> 
> p results  
> --\>[10, 20, 30, 50, 60]

Whoops. That doesn't work because the end of a line is not a comma so  
the last field on a line is combined into a string with the first field  
on the next line, which mucks up the results. You could do something  
like this instead:

results =

File.open("data.txt") do |file|  
&nbsp;&nbsp;file.each\_line() do |record|  
&nbsp;&nbsp;&nbsp;&nbsp;fields = record.split(",")  
&nbsp;&nbsp;&nbsp;&nbsp;fields.each do |field|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results \<\< field.to\_i  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
end

p results

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![John\_Nott](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@John\_Nott](https://rubytalk.org/u/John_Nott)
#### Post date: [8 October 2007 14:10 UTC](https://rubytalk.org/t/matrix-problems-again/41236/4 "2007-10-08T14:10:48Z")

</div>

Hi!  
This seems to work very well thanks but the results are produced in a long string. Is it possible to create these figures as a matrix? (resembling something like excel)  
Thanks for your help.  
- John

> **···**
>
> -----Original Message-----  
> From: list-bounce@example.com [mailto:list-bounce@example.com]On Behalf  
> Of 7stud --  
> Sent: 08 October 2007 15:02  
> To: ruby-talk ML  
> Subject: Re: MATRIX PROBLEMS (AGAIN!)
> 
> 7stud -- wrote:
> 
> > But that is poorly written code; I can see that you copied it off the OT  
> > website. Instead, you can write something like this:
> > 
> > results =
> > 
> > File.open("data.txt") do |file|  
> > &nbsp;&nbsp;file.each\_line(',') do |field|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results \<\< field.to\_i  
> > &nbsp;&nbsp;end  
> > end
> > 
> > p results  
> > --\>[10, 20, 30, 50, 60]
> 
> Whoops. That doesn't work because the end of a line is not a comma so  
> the last field on a line is combined into a string with the first field  
> on the next line, which mucks up the results. You could do something  
> like this instead:
> 
> results =
> 
> File.open("data.txt") do |file|  
> &nbsp;&nbsp;file.each\_line() do |record|  
> &nbsp;&nbsp;&nbsp;&nbsp;fields = record.split(",")  
> &nbsp;&nbsp;&nbsp;&nbsp;fields.each do |field|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results \<\< field.to\_i  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;end  
> end
> 
> p results
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> 
> #####################################################################################  
> This e-mail message has been scanned for Viruses and Content and cleared  
> by MailMarshal  
> #####################################################################################

---

<div class="post-metadata">

### Author: ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)
#### Post date: [8 October 2007 14:11 UTC](https://rubytalk.org/t/matrix-problems-again/41236/5 "2007-10-08T14:11:05Z")

</div>

7stud -- wrote:

> results =
> 
> File.open("data.txt") do |file|  
> &nbsp;&nbsp;file.each\_line() do |record|  
> &nbsp;&nbsp;&nbsp;&nbsp;fields = record.split(",")  
> &nbsp;&nbsp;&nbsp;&nbsp;fields.each do |field|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results \<\< field.to\_i  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;end  
> end
> 
> p results

You can also use the Standard Library module CSV(or get the gem  
FasterCSV) to easily read comma separated data:

require 'csv'

matrix =

CSV.open('data.txt', 'r') do |row|  
&nbsp;&nbsp;row.each do |column|  
&nbsp;&nbsp;&nbsp;&nbsp;matrix \<\< column.to\_i  
&nbsp;&nbsp;end  
end

p matrix  
--\>[10, 20, 30, 40, 50, 60]

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)
#### Post date: [8 October 2007 15:17 UTC](https://rubytalk.org/t/matrix-problems-again/41236/6 "2007-10-08T15:17:29Z")

</div>

John Nott wrote:

> Hi!  
> This seems to work very well thanks but the results are produced in a  
> long string. Is it possible to create these figures as a matrix?  
> (resembling something like excel)  
> Thanks for your help.  
> - John

Here are some guidelines:

1) Start off writing a program that works on a small amount of data,  
e.g. a file with this in it:

10,20,30  
40,50,60

2) Always post an example of the format of your data, so we all know  
what you are dealing with.

3) Clearly state what the results should be. At this point I still  
don't have any idea whether you want integers in your matrix or strings.

4) State what you intend to do with the result, so that people will have  
a better idea of \*what you really need\* rather that what you say you  
want.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![\_Pena\_Botp1](https://avatars.discourse-cdn.com/v4/letter/_/94ad74/32.png) [@\_Pena\_Botp1](https://rubytalk.org/u/_Pena_Botp1)
#### Post date: [9 October 2007 01:29 UTC](https://rubytalk.org/t/matrix-problems-again/41236/7 "2007-10-09T01:29:11Z")

</div>

# This seems to work very well thanks but the results are  
# produced in a long string. Is it possible to create these  
# figures as a matrix? (resembling something like excel)  
# Thanks for your help.

i just modified 7studs's code,

C:\family\ruby\>cat test.txt  
1,2,3  
4,5,6  
7,8,9

C:\family\ruby\>cat test.rb  
results = []  
ARGF.each do |record|  
&nbsp;&nbsp;&nbsp;&nbsp;results \<\< record.split(",").map{|x| x.to\_i}  
end  
p results  
puts  
s=results.size  
s.times do |y|  
&nbsp;&nbsp;s.times do |x|  
&nbsp;&nbsp;&nbsp;&nbsp;print results[y][x],"\t"  
&nbsp;&nbsp;end  
&nbsp;&nbsp;puts  
end

C:\family\ruby\>ruby test.rb test.txt  
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]

1 2 3  
4 5 6  
7 8 9

C:\family\ruby\>ruby test.rb  
1,2,3  
4,5,6,7  
8,9  
10  
^Z  
[[1, 2, 3], [4, 5, 6, 7], [8, 9], [10]]

1 2 3 nil  
4 5 6 7  
8 9 nil nil  
10 nil nil nil

C:\family\ruby\>

hth -botp

> **···**
>
> From: John Nott [[mailto:JNott@dto.ie](mailto:JNott@dto.ie)]

---

<div class="post-metadata">

### Author: ![John\_Nott](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@John\_Nott](https://rubytalk.org/u/John_Nott)
#### Post date: [8 October 2007 16:18 UTC](https://rubytalk.org/t/matrix-problems-again/41236/8 "2007-10-08T16:18:12Z")

</div>

Good Points!!! (hope my explanation makes sense!)

1) Start off writing a program that works on a small amount of data,  
e.g. a file with this in it:

10,20,30  
40,50,60

2) Always post an example of the format of your data, so we all know  
what you are dealing with.

The format of my data is a .csz file which has been created from an excel sheet. It has 19 columns and 649 rows. The first row is a column title (eg: zone\_ID, Population, Population0\_16.... etc) the following rows are all integer values. So its pretty much a standard excel sheet.

3) Clearly state what the results should be. At this point I still  
don't have any idea whether you want integers in your matrix or strings.

I would like (within OmniTrans) to read the data in and store it in a matrix. As a very green ruby programmer (dropped in at the deep end!), If i was able to achieve this, that would be a major milestone for me.

4) State what you intend to do with the result, so that people will have  
a better idea of \*what you really need\* rather that what you say you  
want.

My longer term objective is to do some fixes on this data. For example. I may want to say "look at cell (15,1), if this cell is greater than (15,5) then change this cell to the value of (15,15) - that sort of thing. An even longer term objective is to take the 'fixed' dataset and link it via ODBC to a data warehouse (this is way off as you can imagine)

I hope this helps explain myself and i really appreciate all the help from the listers!!! If i ever get to grips with ruby I will certainly be answering queries!!

Cheers,

- John

> **···**
>
> -----Original Message-----  
> From: list-bounce@example.com [mailto:list-bounce@example.com]On Behalf  
> Of 7stud --  
> Sent: 08 October 2007 16:17  
> To: ruby-talk ML  
> Subject: Re: MATRIX PROBLEMS (AGAIN!)
> 
> John Nott wrote:
> 
> > Hi!  
> > This seems to work very well thanks but the results are produced in a  
> > long string. Is it possible to create these figures as a matrix?  
> > (resembling something like excel)  
> > Thanks for your help.  
> > - John
> 
> Here are some guidelines:
> 
> 1) Start off writing a program that works on a small amount of data,  
> e.g. a file with this in it:
> 
> 10,20,30  
> 40,50,60
> 
> 2) Always post an example of the format of your data, so we all know  
> what you are dealing with.
> 
> 3) Clearly state what the results should be. At this point I still  
> don't have any idea whether you want integers in your matrix or strings.
> 
> 4) State what you intend to do with the result, so that people will have  
> a better idea of \*what you really need\* rather that what you say you  
> want.
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> 
> #####################################################################################  
> This e-mail message has been scanned for Viruses and Content and cleared  
> by MailMarshal  
> #####################################################################################

---

<div class="post-metadata">

### Author: ![John\_Nott](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@John\_Nott](https://rubytalk.org/u/John_Nott)
#### Post date: [9 October 2007 09:23 UTC](https://rubytalk.org/t/matrix-problems-again/41236/9 "2007-10-09T09:23:03Z")

</div>

Hi Thanks for this. Have tried with with the following file called RubyTest.txt  
1,2,3  
4,5,6  
7,8,9

so the code is as follows:

M:\John N\RubyTest.txt  
results = []  
ARGF.each do |record|  
&nbsp;&nbsp;&nbsp;&nbsp;results \<\< record.split(",").map{|x| x.to\_i}  
end  
p results  
puts  
s=results.size  
s.times do |y|  
&nbsp;&nbsp;s.times do |x|  
&nbsp;&nbsp;&nbsp;&nbsp;print results[y][x],"\t"  
&nbsp;&nbsp;end  
&nbsp;&nbsp;puts  
end

However I get the follwoing error message

Error: c:\0kjk\a1\TAGM-ver4\jobs\JN\_Matrix\_3.rb:1:syntax error

M:\John N\RubyTest.txt

c:\0kjk\a1\TAGM-ver4\jobs\JN\_Matrix\_3.rb:3: syntax error  
ARGF.each do |record|

> **···**
>
> -----Original Message-----  
> From: Peña, Botp [[mailto:botp@delmonte-phil.com](mailto:botp@delmonte-phil.com)]  
> Sent: 09 October 2007 02:29  
> To: ruby-talk ML  
> Subject: Re: MATRIX PROBLEMS (AGAIN!)
> 
> From: John Nott [[mailto:JNott@dto.ie](mailto:JNott@dto.ie)]  
> # This seems to work very well thanks but the results are  
> # produced in a long string. Is it possible to create these  
> # figures as a matrix? (resembling something like excel)  
> # Thanks for your help.
> 
> i just modified 7studs's code,
> 
> C:\family\ruby\>cat test.txt  
> 1,2,3  
> 4,5,6  
> 7,8,9
> 
> C:\family\ruby\>cat test.rb  
> results = []  
> ARGF.each do |record|  
> &nbsp;&nbsp;&nbsp;&nbsp;results \<\< record.split(",").map{|x| x.to\_i}  
> end  
> p results  
> puts  
> s=results.size  
> s.times do |y|  
> &nbsp;&nbsp;s.times do |x|  
> &nbsp;&nbsp;&nbsp;&nbsp;print results[y][x],"\t"  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;puts  
> end
> 
> C:\family\ruby\>ruby test.rb test.txt  
> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
> 
> 1 2 3  
> 4 5 6  
> 7 8 9
> 
> C:\family\ruby\>ruby test.rb  
> 1,2,3  
> 4,5,6,7  
> 8,9  
> 10  
> ^Z  
> [[1, 2, 3], [4, 5, 6, 7], [8, 9], [10]]
> 
> 1 2 3 nil  
> 4 5 6 7  
> 8 9 nil nil  
> 10 nil nil nil
> 
> C:\family\ruby\>
> 
> hth -botp
> 
> #####################################################################################  
> This e-mail message has been scanned for Viruses and Content and cleared  
> by MailMarshal  
> #####################################################################################

---

<div class="post-metadata">

### Author: ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)
#### Post date: [8 October 2007 16:58 UTC](https://rubytalk.org/t/matrix-problems-again/41236/10 "2007-10-08T16:58:29Z")

</div>

John Nott wrote:

> Good Points!!! (hope my explanation makes sense!)
> 
> 1) Start off writing a program that works on a small amount of data,  
> e.g. a file with this in it:
> 
> 10,20,30  
> 40,50,60
> 
> 2) Always post an example of the format of your data, so we all know  
> what you are dealing with.
> 
> The format of my data is a .csz file which has been created from an  
> excel sheet. It has 19 columns and 649 rows. The first row is a column  
> title (eg: zone\_ID, Population, Population0\_16.... etc) the following  
> rows are all integer values. So its pretty much a standard excel sheet.

No, no, no. See 1). Posting an example of the format of your data  
would look like this:

10, 20, 4

or

3,6,7

> 3) Clearly state what the results should be. At this point I still  
> don't have any idea whether you want integers in your matrix or strings.
> 
> I would like (within OmniTrans) to read the data in and store it in a  
> matrix. As a very green ruby programmer (dropped in at the deep end!),  
> If i was able to achieve this, that would be a major milestone for me.

As far as I can tell OmniTrans is not a ruby gem, nor is it is easy to  
locate a download, so I think you are on your own for that part of it.

> 4) State what you intend to do with the result, so that people will have  
> a better idea of \*what you really need\* rather that what you say you  
> want.
> 
> My longer term objective is to do some fixes on this data. For example.  
> I may want to say "look at cell (15,1), if this cell is greater than  
> (15,5) then change this cell to the value of (15,15) - that sort of  
> thing. An even longer term objective is to take the 'fixed' dataset and  
> link it via ODBC to a data warehouse (this is way off as you can  
> imagine)

Ok. The code I posted shows you how to get the data from a file and  
turn it into an integer; it's up to you to put it in Omni Trans the way  
you want. Once again, to make things easier on yourself start with a  
file that contains 2 lines of data, and then you should get be able to  
get something working.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)
#### Post date: [9 October 2007 09:52 UTC](https://rubytalk.org/t/matrix-problems-again/41236/11 "2007-10-09T09:52:20Z")

</div>

John Nott wrote:

> However I get the follwoing error message
> 
> Error: c:\0kjk\a1\TAGM-ver4\jobs\JN\_Matrix\_3.rb:1:syntax error
> 
> M:\John N\RubyTest.txt

Is it your understanding that this line is ruby code:

M:\John N\RubyTest.txt

What do you think it does?

You are supposed to be learning to write programs here--not just copying  
and pasting text.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![John\_Nott](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@John\_Nott](https://rubytalk.org/u/John_Nott)
#### Post date: [9 October 2007 10:40 UTC](https://rubytalk.org/t/matrix-problems-again/41236/12 "2007-10-09T10:40:30Z")

</div>

OK fair point!  
Tried it like this:

File.open("M:\\John N\\RubyTest\\Test.txt") do |file|

results =

File.each do |record|  
&nbsp;&nbsp;&nbsp;&nbsp;results \<\< record.split(",").map{|x| x.to\_i}  
end  
p results  
puts  
s=results.size  
s.times do |y|  
&nbsp;&nbsp;s.times do |x|  
&nbsp;&nbsp;&nbsp;&nbsp;print results[y],"\t"  
&nbsp;&nbsp;end  
&nbsp;&nbsp;puts  
end

Giving me a syntax error in line 18 though (as in the last 'end')

which is the same even when i remove it!

> **···**
>
> -----Original Message-----  
> From: list-bounce@example.com [mailto:list-bounce@example.com]On Behalf  
> Of 7stud --  
> Sent: 09 October 2007 10:52  
> To: ruby-talk ML  
> Subject: Re: MATRIX PROBLEMS (AGAIN!)
> 
> John Nott wrote:
> 
> > However I get the follwoing error message
> > 
> > Error: c:\0kjk\a1\TAGM-ver4\jobs\JN\_Matrix\_3.rb:1:syntax error
> > 
> > M:\John N\RubyTest.txt
> 
> Is it your understanding that this line is ruby code:
> 
> M:\John N\RubyTest.txt
> 
> What do you think it does?
> 
> You are supposed to be learning to write programs here--not just copying  
> and pasting text.  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> 
> #####################################################################################  
> This e-mail message has been scanned for Viruses and Content and cleared  
> by MailMarshal  
> #####################################################################################

---

<div class="post-metadata">

### Author: ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)
#### Post date: [9 October 2007 10:57 UTC](https://rubytalk.org/t/matrix-problems-again/41236/13 "2007-10-09T10:57:35Z")

</div>

John Nott wrote:

> Giving me a syntax error in line 18 though (as in the last 'end')
> 
> which is the same even when i remove it!

Well, then add an end. 🙂

open("M:\\John N\\RubyTest\\Test.txt") do |file|

&nbsp;&nbsp;&nbsp;&nbsp;results =

&nbsp;&nbsp;&nbsp;&nbsp;File.each do |record|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results \<\< record.split(",").map{|x| x.to\_i}  
&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;p results  
&nbsp;&nbsp;&nbsp;&nbsp;puts

&nbsp;&nbsp;&nbsp;&nbsp;s=results.size  
&nbsp;&nbsp;&nbsp;&nbsp;s.times do |y|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.times do |x|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print results[y],"\t"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts  
&nbsp;&nbsp;&nbsp;&nbsp;end

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

### Author: ![John\_Nott](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@John\_Nott](https://rubytalk.org/u/John_Nott)
#### Post date: [9 October 2007 11:02 UTC](https://rubytalk.org/t/matrix-problems-again/41236/14 "2007-10-09T11:02:17Z")

</div>

you're a genius!! and get this - I even figured out another error I had in there - File.each should of course be file.each

looks like i'm learning after all 😉

Thanks a million for your help!!!

> **···**
>
> -----Original Message-----  
> From: list-bounce@example.com [mailto:list-bounce@example.com]On Behalf  
> Of 7stud --  
> Sent: 09 October 2007 11:58  
> To: ruby-talk ML  
> Subject: Re: MATRIX PROBLEMS (AGAIN!)
> 
> John Nott wrote:
> 
> > Giving me a syntax error in line 18 though (as in the last 'end')
> > 
> > which is the same even when i remove it!
> 
> Well, then add an end. 🙂
> 
> open("M:\\John N\\RubyTest\\Test.txt") do |file|
> 
> &nbsp;&nbsp;&nbsp;&nbsp;results =
> 
> &nbsp;&nbsp;&nbsp;&nbsp;File.each do |record|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results \<\< record.split(",").map{|x| x.to\_i}  
> &nbsp;&nbsp;&nbsp;&nbsp;end
> 
> &nbsp;&nbsp;&nbsp;&nbsp;p results  
> &nbsp;&nbsp;&nbsp;&nbsp;puts
> 
> &nbsp;&nbsp;&nbsp;&nbsp;s=results.size  
> &nbsp;&nbsp;&nbsp;&nbsp;s.times do |y|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.times do |x|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print results[y],"\t"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts  
> &nbsp;&nbsp;&nbsp;&nbsp;end
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> 
> #####################################################################################  
> This e-mail message has been scanned for Viruses and Content and cleared  
> by MailMarshal  
> #####################################################################################

---

<div class="post-metadata">

### Author: ![7stud1](https://avatars.discourse-cdn.com/v4/letter/7/59ef9b/32.png) [@7stud1](https://rubytalk.org/u/7stud1)
#### Post date: [9 October 2007 11:38 UTC](https://rubytalk.org/t/matrix-problems-again/41236/15 "2007-10-09T11:38:29Z")

</div>

John Nott wrote:

> and get this - I even figured out another error I had  
> in there - File.each should of course be file.each
> 
> looks like i'm learning after all 😉

Nice. Well done.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
