From: Brian Candler Date: 2004-10-10T00:50:10+09:00 Subject: Re: split file into 2D array On Sun, Oct 10, 2004 at 12:44:50AM +0900, Arthur Korneyew wrote: > I just tried: > > a = [[],[]] > IO.foreach("words.txt") {|line| > unless line.strip.empty? | (line =~ (/^\#/)) > string = line.chomp.split > a << string > end > } > > #puts a > puts [0][1] > > [root@tequila2 logs]# ./logs5.rb > nil > > If I tried to print second element from array (it should be word2),I > have got nil. Useful debug tool: put at the end puts a.inspect or p a and you'll see what's wrong. It's find except you put an initial empty row in there. Either change the first line to a = [] # array with no elements or else do puts a[1][0], a[1][1] to get the first useful element. Regards, Brian.