tags:

views:

68

answers:

2

Hi, 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 :)

+5  A: 

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.

Eric W.
I don't have the luxury of doing that, the other problem is that there are literally hundreds of scripts preforming this same maneuver. We use them as configuration files unfortunately.
sploit
Hmm. Is saving the Dumper exports as config files an architectural decision you can revisit? It seems like a bad idea in the long run.
Eric W.
A: 

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
Lars Haugseth