file.puts define newline

M

MrBanabas

Hi,

just would like to know if I can somehow define the newline delimeter
when using file.puts ?
e.g. /n, /r/n

Thanks a lot in advance...
 
B

badboy

Hi,

just would like to know if I can somehow define the newline delimeter
when using file.puts ?
e.g. /n, /r/n

Thanks a lot in advance...
hm...I don't think so.
Can't you use file.print and append a "\r\n" or whatever you need?
 
M

MrBanabas

(e-mail address removed) schrieb:> Hi,



hm...I don't think so.
Can't you use file.print and append a "\r\n" or whatever you need?

Sure I can do that, but I thought it would be "cleaner" if I could to
something like:
file = new File....
file.newline_delimiter = '/r/n'
or
file.newline_delimiter = 'dos'
 
B

badboy

Sure I can do that, but I thought it would be "cleaner" if I could to
something like:
file = new File....
file.newline_delimiter = '/r/n'
or
file.newline_delimiter = 'dos'
ugly... newline_delimiter = '/r/n' wouldn't work as you expected =D
it should be \r\n right?
 
7

7stud --

Sure I can do that, but I thought it would be "cleaner" if I could to
something like:
file = new File....
file.newline_delimiter = '/r/n'
or
file.newline_delimiter = 'dos'

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
 
7

7stud --

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top