Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: "eval"ing a hash without eval

by qq (Hermit)
on Dec 29, 2005 at 14:40 UTC ( [id://519792]=note: print w/replies, xml ) Need Help??


in reply to "eval"ing a hash without eval

Would it be that hard to convert to a sane setup? Make a little script that evals each config file as shown, then YAML::Dump's it out to another replacement config file...

The calling code would (probably) be easy to replace. This would lose any comments. But you mentioned the the config file is written to in multiple places, and I can't see how the comments would be getting added anyway in that case. I have a feeling I'm missing the complexity here...

$ cat hash.conf foo => 'bar', baz => 'quux', $ perl -MYAML -0 -e '%h=eval<>; YAML::DumpFile( "$ARGV\.yml", \%h)' ha +sh.conf $ cat hash.conf.yml --- baz: quux foo: bar $ perl -MYAML -MData::Dumper -e '$h = YAML::LoadFile( shift() ); print + Dumper $h' hash.conf.yml $VAR1 = { 'baz' => 'quux', 'foo' => 'bar' };

Replies are listed 'Best First'.
Re^2: "eval"ing a hash without eval
by Aristotle (Chancellor) on Dec 29, 2005 at 16:45 UTC

    You write:

    Would it be that hard to convert to a sane setup?

    Ovid wrote:

    I could either spend two or three days ripping out all of the configuration code which writes to that file and replace it with a standard configuration set up, find a module on the CPAN which implements this or I could reinvent the wheel.

    And then Ovid wrote again:

    That config file is autogenerated. As mentioned in my post, it would take me two or three days (I hope) to rip out everything which writes to that file and replace it. Instead, I hacked a solution in a couple of hours.

    Your suggestion (or something very close) has already been made twice by others after it was preempted by the original node, and was then refuted once more in replies.

    Makeshifts last the longest.

      I had somehow missed the reply to BrowserUk when I posted. I did write I have a feeling I'm missing the complexity here. And it did occur to me that Ovid was unlikely to have overlooked any simple solutions.

      After seeing the reply to BrowserUk I considered updating my original. But I could think of nothing actually useful to add. So instead everybody gets your entirely accurate but somewhat snotty reply, and my waste-of-space defensive rebuttal. Luckily we are all professional enough not to take offense ;)

        And it did occur to me that Ovid was unlikely to have overlooked any simple solutions.

        I have, on numerous occassions, missed blindingly obvious solutions, so I rarely mind them being pointed out to me.

        Cheers,
        Ovid

        New address of my CGI Course.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://519792]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-18 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found