Robert Klemme wrote: > If I understood you properly: > > # untested > last_name = nil > io = nil > begin > data.sort_by {|d| d.location}.each do |d| > output_filename = "#{d.location}.txt" > > unless output_filename == last_name > io.close rescue nil > io = File.open(output_filename, "a") > end > > io.puts d.file_name > ensure > io.close rescue nil > end Yes, that looks like just the job, thanks. I was trying something similar but without the begin/ensure/end block and that is presumably why I was having difficulty. -- Posted via http://www.ruby-forum.com/.