From: "Jesús Gabriel y Galán" Date: 2009-06-09T22:31:12+09:00 Subject: Re: "puts"ing an array On Tue, Jun 9, 2009 at 2:52 PM, Peter Bailey wrote: > Hi, > In the "pickaxe" book I see how to use a "puts" to populate a file with > data. I try the same thing, and, it works, but, it's listing the data as > an array. How can I get separate lines for each item in the array? > Thanks, > Peter > > In the book: >  File.open("output.txt", "w") do |file| >  file.puts "Hello" >  file.puts "1 + 2 = #{1+2}" >  end >  # Now read the file in and print its contents to STDOUT >  puts File.read("output.txt") > produces: >  Hello >  1 + 2 = 3 > > My script: >  Dir.chdir("L:/png/69000") >  files = Dir.glob("*.png") >  File.open("F:/workflows/graphics/receipts/pngfiles.txt", "w") do |file| >  file.puts "#{files}" >  end > produces: >  69116.png69251.png69391.pngAZ69080.pngAZ69982.pngcx69362.pngcx69363.png Dir.glob returns an array, so two possibilities are (untested): File.open("F:/workflows/graphics/receipts/pngfiles.txt", "w") do |file| file.puts files.join("\n") end File.open("F:/workflows/graphics/receipts/pngfiles.txt", "w") do |file| files.each {|f| file.puts f } end Hope this helps, Jesus.