From: Robert Dober Date: 2007-01-13T02:47:39+09:00 Subject: Re: DRY gsub... ------=_Part_45921_27139730.1168624056891 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 1/12/07, James Edward Gray II wrote: > > On Jan 12, 2007, at 11:35 AM, Robert Dober wrote: > > > On 1/12/07, Josselin wrote: > >> > >> I wrote the following ruby statements.. I get the result I need , I > >> tried to DRY it for 2 hours without being successfull , > >> > >> d = d.gsub(/\r\n/,' ') # get rid of carriage return > >> d = d.gsub(/;/,' ') # replace column by space > >> d = d.gsub(/,/,' ') # replace comma by space > >> a = d.split(' ') # split into component , space as divider > >> > >> tfyl > >> > >> Joss > > > > > > I know you got lots of answers but what about > > > > a = d.gsub(/;|,/," ").split > > No need for a Regexp there: > > a = d.tr(";,", " ").split > > James Edward Gray II > > Nice one ( I thought I got it optimal, naaa) and faster too of course :) robert@PC:~/log/ruby/ML 18:46:00 535/35 > ruby split.rb split.rb Rehearsal --------------------------------------------- regex 4.891000 0.000000 4.891000 ( 4.602000) translate 3.812000 0.000000 3.812000 ( 3.685000) ------------------------------------ total: 8.703000sec user system total real regex 5.016000 0.000000 5.016000 ( 4.669000) translate 3.859000 0.000000 3.859000 ( 3.805000) Cheers Robert ------=_Part_45921_27139730.1168624056891--