in reply to Re: Re: Re: Reading and *writing* configuration files
in thread Reading and *writing* configuration files

<sarcasm>No kidding?</sarcasm> That's *kinda* what I'm looking for help with. Parsing the named.conf file was easy enough and, as you mentioned, I could have used Bind::Conf as a starting point for that.

What I'm looking for is tip on writing a new, updated, config file back out.

Maybe some more information would help. I'm currently writing a fresh new config (with no comments or formatting etc preserved from the original) to a temp file. Then I copy the old file to a .bak extension and copy the temp file over the /etc/named.conf file.

So far so good. But I posted this query in the hopes that with all the massive knowledge and experience that the combined readers of PerlMonks have, that someone will have either tips on ways to improve this procedure or warning about things I might be doing badly.

Maybe I should have been more clear in my initial post. Still, there have been some pretty good suggestions posted here and I definately feel more confident of what direction I should go in.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Reading and *writing* configuration files
by tachyon (Chancellor) on Apr 10, 2002 at 22:39 UTC

    OK. First you will get more help if you are not rude. Second it is more efficient to do:

    renane /etc/named.conf /etc/named.conf.bak or die $!; open BIND, ">/etc/named.conf" or die $!; print BIND "DeathBunny!";

    I assume that you don't understand the callback/subclassing parsing strategy used by a number of perl parsers. Essentially what happens is that the parser rips through the file and passes the chunks of info it finds to a range of handlers. You will find a simple HTML::Parser example of mine at Re: Tag filtering: a standard mechanism?. This should give you the general idea. You will either be writing to your new file from these callback subs or storing the data in a data structure of your choosing for later post processing and file write.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print