Reputation: 2692
I use this line to read from temp.dat, which contains "100"
fahrenheit = IO.read("temp.dat").to_i * 9 / 5 + 32
Now, to write this result in another file;
Method 1
f = File.new("temp.out", "w")
f.puts fahrenheit
cat temp.out
212
Method 2
IO.write("temp.out", fahrenheit)
cat temp.out
212%
Upvotes: 0
Views: 45
Reputation: 230346
Why does my IO.write insert a “%” sign at the end of output?
It doesn't. Here's the binary content of the file. That %
character is the command prompt of your shell, which is confused by the lack of EOL in the file. POSIX-compliant text files should always end lines with end-of-line character.
Upvotes: 2