From: Austin Ziegler Date: 2005-03-01T06:02:27+09:00 Subject: Re: catting files On Tue, 1 Mar 2005 05:17:03 +0900, Mark Probert wrote: > There is approximately an order of magnitude difference in the > performance of these two snippets. Is there a faster way of doing > the pure Ruby version? > ### use the system call 'cat' > def sys_cat > of = "plato.txt.cat" > clean(of) > l = `cat Plato/*.txt > #{of}` > end def faster_cat of = "plato.txt.fct" clean(of) File.open(of, "wb+") do |outf| Dir["Plato/*.txt"].each do |inf| outf.puts IO::read(inf) end end end As I don't have the "Plato/*.txt" files, I can't test it, but that you're not splitting the file into multiple lines and iterating over them will be faster. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca