From: George George Date: 2009-06-15T21:12:12+09:00 Subject: Re: formatting a listing Robert Dober wrote: > On Mon, Jun 15, 2009 at 12:46 PM, George > George wrote: >> 3 >> any ideas? >> thanks > > If this is a homework assignement I am terribly sorry, but I cannot > know. > > puts DATA.inject( [ [] ] ){ | ary, ele | > ele.strip.empty? ? ary << [] : ary.last << ele.to_i # or ele.chomp > if you prefer > ary > } > .reject( &:empty? ) # .map( &:join, ", " ) is not standard Ruby > .map{ | eles | eles.join( ", " )} > > __END__ > 1 > 2 > > 42 > 44 > 46 > > 2000 > > HTH > Robert Thank so much for pointing the way: And this is not assignment! :) Am working on some huge datasets that run in to up to 20 000 columns and was looking for an easy way of creating the columns. puts DATA.inject( [ [] ] ){ | ary, ele | ele.strip.empty? ? ary << [] : ary.last << ele.to_i # or ele.chomp #if you prefer # ary } #.reject( &:empty? ) # .map( &:join, ", " ) is not standard Ruby #.map{ | eles | eles.join( ", " )} __END__ 1 2 42 44 46 am not trying to ask too much but your code is real witchcraft :) raises an error `<<': can't convert Array into Integer (TypeError) -- Posted via http://www.ruby-forum.com/.