# Re: MATRIX PROBLEMS (AGAIN!)

**URL:** <https://www.ruby-forum.com/t/re-matrix-problems-again/116653>\
**Category:** Ruby\
**Created:** [October 8, 2007, 2:25pm UTC](https://www.ruby-forum.com/t/re-matrix-problems-again/116653 "2007-10-08T14:25:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [October 8, 2007, 2:25pm UTC](https://www.ruby-forum.com/t/re-matrix-problems-again/116653/1 "2007-10-08T14:25:53Z")

</div>

Hi John

Instead of this:  
line.each(’,’) { |this\_record|  
fields \<\< this\_record.chomp(",").strip() # read to the end  
of the  
file into ‘fields’, split into lines and chomp out the delimiter  
mat1[r,c] = fields[r,c] # the rows  
and  
columns in the matrix = rows and columns in fields  
c=c+1  
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  
}  
which I think is the problem,

try

fields = eval("[" + line + “]”)

this should turn the string into an array which you can iterate over -  
this comes from the Hal F. book so it should work.

HTH

Clive
