From: Jim Freeze Date: 2003-04-25T19:28:04+09:00 Subject: Re: parsing large file into matrix On Friday, 25 April 2003 at 19:18:40 +0900, Robert Klemme wrote: > > "Jim Freeze" schrieb im Newsbeitrag > news:20030425002319.A47026@freeze.org... > > On Thursday, 24 April 2003 at 19:08:17 +0900, Robert Klemme wrote: > > > > > Here's a common scenario that I use. > > This file allows comments that start with '#'. > > All other lines that are not empty are data. > > > > def to_number(str) > > Integer(str) rescue Float(str) rescue str > > end > > > > matrix = [] > > File.foreach(file) { |line| > > next if /^\s*$/ =~ line > > next if /^\s*#/ =~ line > > matrix << line.strip.split(/\t/).collect { |i| to_number(i) } > > } > > next if /^\s*(#.*)?$/ =~ line > > sorry, couldn't resist. :-) Sorry, I don't understand. Are you trying to capture the comment and then throw it away? -- Jim Freeze ---------- If I had a plantation in Georgia and a home in Hell, I'd sell the plantation and go home. -- Eugene P. Gallagher