From: Robert Dober Date: 2009-06-15T20:08:59+09:00 Subject: Re: formatting a listing On Mon, Jun 15, 2009 at 12:46 PM, George George wrote: > i have a listing which looks like this > 1 > 2 > 3 > > 3 > 4 > 5 > > 20 > 3 > 5 > 5 > > i would like a quick way to format that output such that i end up with 3 > columns like the following. > 1,2,20 > 2,4,3 > 3,5,5 >    5 > > 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 -- Toutes les grandes personnes ont d’abord été des enfants, mais peu d’entre elles s’en souviennent. All adults have been children first, but not many remember. [Antoine de Saint-Exupéry]