J
joemacbusiness
Hi All,
How do I read an input file and print it back to STDOUT
exactly as the original file. This should be very simple
but the output of my program is all garbled.
What am I doing wrong?
( I am using http://www.rubycentral.com/book to learn Ruby)
The program, input, and runtime output are below.
Thanks, --JM
================= snip ==============
$ cat ./test56.rb
#!/usr/local/bin/ruby
inputFile = File.readlines("input4", 'r')
for item in inputFile
item.chop()
print item, "\n"
end
$
$ cat input4
car
tree
house
candy bar
paper
ocean
$ ./test56.rb
car
tr
ee
house
candy bar
paper
ocean
How do I read an input file and print it back to STDOUT
exactly as the original file. This should be very simple
but the output of my program is all garbled.
What am I doing wrong?
( I am using http://www.rubycentral.com/book to learn Ruby)
The program, input, and runtime output are below.
Thanks, --JM
================= snip ==============
$ cat ./test56.rb
#!/usr/local/bin/ruby
inputFile = File.readlines("input4", 'r')
for item in inputFile
item.chop()
print item, "\n"
end
$
$ cat input4
car
tree
house
candy bar
paper
ocean
$ ./test56.rb
car
tr
ee
house
candy bar
paper
ocean