From: "Wayne E. Seguin" Date: 2007-09-21T10:40:27+09:00 Subject: Re: I am new to Ruby and I could use some expert advice as to how I can make this code run faster. --Apple-Mail-23--569246641 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Sep 20, 2007, at 18:05 , Ruby Maniac wrote: > I am new to Ruby and I could use some expert advice as to how I can > make this code run faster. > > def scramble(fname) > f = File.new(fname, "rb") > _fname = fname + ".scrambled" > begin > File.exist?(_fname) if File.delete(_fname) > rescue > end > ff = File.new(_fname, "wb+") > for l in f > l.each_byte{|c| ff.write((c | 0x80).chr) } > end > f.close() > ff.close() > end One thing that you should do is get rid of that rescue block, that *should speed it up some: - begin - File.exist?(_fname) if File.delete(_fname) - rescue - end + File.delete(_fname) if File.exist? ~Wayne s///g Wayne E. Seguin Sr. Systems Architect & Systems Administrator --Apple-Mail-23--569246641--