7stud said:
You are supposed to be able to do this:
$OUTPUT_RECORD_SEPARATOR = "apple"
f = File.open("data.txt", "w")
f.write "hello world"
f.write "goodbye"
f.close()
but the output I get in data.txt is:
hello worldgoodbye
Ok, I found one combination that allows me to define the output
separator:
1) Use this assignment:
$\ = "apple"
2) And the new output record separator only works with print(), not
write():
#$OUTPUT_FIELD_SEPARATOR = "apple"
$\ = "apple"
x = "hello world"
y = "goodbye"
f = File.open("data.txt", "w")
f.write x
f.write y
f.close #data.txt => hello worldgoodbye
STDOUT.write x
STDOUT.write y #terminal => hello worldgoodbye
f = File.open("data.txt", "w")
f.print x
f.print y
f.close #data.txt => hello worldapplegoodbyeapple
print x
print y #terminal => hello worldapplegoodbyeapple