Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Re: Reading and *writing* configuration files

by tachyon (Chancellor)
on Apr 09, 2002 at 15:20 UTC ( [id://157749]=note: print w/replies, xml ) Need Help??


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

Ah that's kinda the idea. You read in the current file and parse it using a parser module. *You* make your changes to this parsed data set. *You* print out the new file from your munged data set.

One significant problem with retaining comments is that they are only useful if the are relevant. Comments that relate to parts of the file which have been changed are worse than useless.

cheers

tachyon

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

  • Comment on Re: Re: Re: Reading and *writing* configuration files

Replies are listed 'Best First'.
Re: Re: Re: Re: Reading and *writing* configuration files
by DeathBunny (Sexton) on Apr 10, 2002 at 21:38 UTC
    <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.

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found