Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

creating output to a file in a single column

 
Greenhorn
Posts: 4
  • 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!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try appending a newline to entry?
 
ric stewart
Greenhorn
Posts: 4
  • 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
  • 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.
 
This is my favorite show. And this is my favorite tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic