Reputation: 1
I'm new to ruby however it isn't really that drastic of a change coming from perl, anyways 've written a simple script to convert my gobs of perl Data::Dumper output into yaml configs, my problem is I'm using eval to accomplish this and seeing as I may like others to use this script one day I would like to eliminate eval for something more sane.
example:
input file contains
$VAR1 = { 'object' => { 'some_key' => 'some_value' } }
method to read it in
# read in file here ...
eval( stringified_file )
print $VAR1.to_yaml
output
object:
some_key: some_value
Thanks :)
Upvotes: 0
Views: 518
Reputation: 14881
If for you're unable to change the source application to output YAML, use Kernel#load:
require 'yaml'
load 'dumped_file', true
puts $VAR1.to_yaml
Upvotes: 0
Reputation: 7571
On the Perl side you can output your data structures to YAML (I like YAML::Syck for this), and then read the data in as YAML on the Ruby side. That way you won't need to do an eval.
Upvotes: 5