From: Brian Candler Date: 2003-04-24T17:55:38+09:00 Subject: Re: parsing large file into matrix On Thu, Apr 24, 2003 at 02:26:08PM +0900, Qubert wrote: > Is there a Ruby-way of creating an m by n array from the beginning? > I know the following doesn't work but something like it code would be nice: > x = File.open("file.txt").readlines.split('\t') x = File.open("file.txt").readlines.collect! do |line| line.chomp.split("\t") end Although that leaves the file open until garbage collection time. The following does not have that problem; it also processes the lines as they are read. x = File.open("file.txt") do |f| f.collect do |line| line.chomp.split("\t") end end Regards, Brian.