This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating output to a file in a single column

 
ric stewart
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create an output file with a single column of data. What I'm using now creates one huge string in my output file:

outFile = File.new("C:/my_ruby_code/output_file.txt", "w")
myFile.each do |element|
outFile.syswrite(element)
end
outFile.close

I've a idea that I should be using print_f with some kind of formatting but I can not find an example anywhere. Any help? Thanks!
 
Steve Nicholson
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try appending a newline to entry?
 
ric stewart
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve - Part of my purpose for writing a routine for scrubbing files is to avoid using these two offenders \n \r . Here's what works so far:

myFile = Array.new
myFile =File.readlines("C:/my_ruby_code/list_of_php_array_functions.txt")
myFile.collect! {|element| element.strip}
myFile.collect! {|element| '"'+element+'"'} # I'm adding double quotes so these elements can get stuffed into a php array

File.open("C:/my_ruby_code/output_file.txt", "w") do |line|
line.puts myFile
end

 
Steve Nicholson
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Offenders?"

How on earth do you plan on putting each entry on a single line without the proper line delimiters?

puts works because it places the "offender" at the end of the line.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic