• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

creating output to a file in a single column

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try appending a newline to entry?
 
ric stewart
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic