wood burning stoves*
The moose likes Ruby and the fly likes creating output to a file in a single column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Ruby
Bookmark "creating output to a file in a single column" Watch "creating output to a file in a single column" New topic
Author

creating output to a file in a single column

ric stewart
Greenhorn

Joined: Nov 18, 2009
Posts: 4
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!


Everything depends on the key, the whole key, and nothing but the key so help me Codd.
Steve Nicholson
Greenhorn

Joined: Nov 18, 2009
Posts: 3
Did you try appending a newline to entry?
ric stewart
Greenhorn

Joined: Nov 18, 2009
Posts: 4
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

Joined: Nov 18, 2009
Posts: 3
"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.
 
wood burning stoves
 
subject: creating output to a file in a single column
 
Similar Threads
hibernate: how to create one-column table for set
Formatted output - any ideas?
Want Help Reagarding Reading Text
need to generate some numbers using loop, the number of times condition met
parse siblings in DOM