In article <ae5c96cb.0401260829.63d13a13 / posting.google.com>,
Qubert <qubert / orbit.gotdns.com> wrote:
>I am in the middle of writing a wrapper to FORTRAN programs using
>Ruby.  It going great so far.  The problem that I need this groups
>help to solve follows:
>
>For the purposes of a reference, a log and to allow continuation of
>the script, I have created a function that writes inquired values to a
>file, as follows:
>
>def savevaribles
>  fs = File.new("./savedvaribles.rb","w")
>  # Saved variables from harmprocessing.rb
>  fs.puts "# Saved variables from harmprocessing.rb"
>  fs.puts "$year = #{$year}"
>  fs.puts "$gonl = #{$gonl}"
>  fs.puts "$tm = #{$tm}"
>  fs.puts "$timezone = #{$timezone}"
>  fs.close
>end
>
>Which creates a file that I can "load" with all my variables.

[...]

Have you considered using YAML?  YAML (well syck) comes with Ruby 1.8.x
and encodes values; this makes it possible to save nils and strings with
"dangerous content" e.g.

[mike@ratdog mike]$ irb
>> require 'yaml'
=> true
>> data = { 'foo' => "lots\nof\nlines", 'bar' => nil }
=> {"foo"=>"lots\nof\nlines", "bar"=>nil}
>> File.open('/tmp/yaml.dat', 'w') do |f|
?>   f << data.to_yaml
>> end
=> #<File:/tmp/yaml.dat (closed)>
>> read_data = YAML::load(File.open('/tmp/yaml.dat'))
=> {"foo"=>"lots\nof\nlines", "bar"=>nil}
>> read_data['bar'].nil?
=> true
>> puts read_data['foo']
lots
of
lines
=> nil

Hope this helps,

Mike

-- 
mike / stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA 
mike / exegenix.com                  | Fingerprint      0570 71CD 6790 7C28 3D60
http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599 13DA