Reading in a file

hi,

i want to create a ruby program that uses a “database” of reference
specifications held in a text file to process a set of other files that
cite these references, substituting correct citations in the text and
adding a reference section to the text after the last file has been
processed. All the output should be sent to the standard output (except
errors which should go to standard error). To format the references i
need to use HTML tags. Some useful tags :

bold italic underline superscript

i cant find out how to read in the file. where should i save the text
file on the computer? and where will the new file appear?

thanks

Chris Daves wrote:

i want to create a ruby program that uses a “database” of reference
specifications held in a text file to process a set of other files that
cite these references, substituting correct citations in the text and
adding a reference section to the text after the last file has been
processed. All the output should be sent to the standard output (except
errors which should go to standard error). To format the references i
need to use HTML tags. Some useful tags :

bold italic underline superscript

i cant find out how to read in the file. where should i save the text
file on the computer? and where will the new file appear?

Answer here:
http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/8aae24bd9706805f#

I suggest you stop using ruby-forum until it is fixed, and instead use
another source that lets you see the answers people are providing.

Chris Daves wrote:

bold italic underline superscript

i cant find out how to read in the file. where should i save the text
file on the computer? and where will the new file appear?

thanks

Look at the doc for the File class and the IO class. File inherits from
IO so all the methods in IO are available in File.

You can save the text file anywhere. When you open the file for reading
you have to tell Ruby - actually the File.open method - where it is. For
example if you save the file in “C:\My Documents\references.txt” then
you have to tell File.open to open “C:\My Documents\references.txt”.
File.open can open any disk file, as long as you tell it which one to
open.

“Standard output” is the console by default, so since you’re writing the
new file to standard output, the new file will appear on your console
unless you redirect standard output to a file, in which case the new
file will appear where ever you redirected standard output. Redirecting
is a function of the command processor or shell, not Ruby. Typically you
redirect standard output by using “>filename” on the command line. For
example, the following command redirects standard output to a file
called "myoutput.txt in the current directory:

ruby mypgm.rb >myoutput.txt

Ruby uses special variables to that represent standard output and
standard error. See the doc on $stdout and $stderr.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs