From: John Carter Date: 2008-10-28T09:18:14+09:00 Subject: Re: Join all text files in a folder, with a single line of Ruby code On Sun, 26 Oct 2008, Robert Klemme wrote: >> File.open("mrg","w"){|f|f.puts Dir['*.txt'].map{|nm|IO.read nm}} > > That's vastly inefficient since it reads all the files into memory before > writing a single byte. This is not necessary. You can at least improve to > > File.open("mrg","w"){|f|Dir['*.txt'].each{|nm|f.write(File.read(nm))}} If we're into fast and ugly... We need a Ruby interface to Linux "splice"... splice() moves data between two file descriptors without copying between kernel address space and user address space. It transfers up to len bytes of data from the file descriptor fd_in to the file descriptor fd_out, where one of the descriptors must refer to a pipe. See "man splice" for more. John Carter Phone : (64)(3) 358 6639 Tait Electronics Fax : (64)(3) 359 4632 PO Box 1645 Christchurch Email : john.carter@tait.co.nz New Zealand