Ok... here is another, and I beg your forgiveness, Masters, but this lowly one has not partaken of perl for quite some time.

I have the following bit of code, using DNS::ZoneParse. The ultimate goal is to have a script that will read a list of zonefiles, and act on each one. In the act, it will then A: reformat the zone file (many of ours are hand written and NOT in any form of standardized format (they do meet specs for zone files, but are not easy to read), and B, update various parts of the SOA records. I am interested in updating the Refresh, TTL, minimumTTL, retry, etc for each listed domain.

For now, the only thing this does is update the serial, but it DOES successfully parse the original zone file and create a new zone file based on the old.

I can sucessfully ADD A, CNAME, MX and such records, but I dont need that at the moment, and have removed those routines for now. What I need to ask of you, is can you show me a way, or ways to manipulate the HASH that is created from the SOA. The code below reads it in, and serial can be updated easily, but I cant figure out how to change the rest. I tried a push (as shown in the sample) but that is no good, becuase the soa is not read as an array.

and yes, the majority of this did come directly from the docs for DNS::ZoneParse. The basic examples are great, but what I need to do is not really explained in the docs, and I am but a mere babe in perl-land.
####BEGIN CODE######

#!/usr/bin/perl use strict; use DNS::ZoneParse; my $zonefile = DNS::ZoneParse->new("./zondervan.com"); print "Current A Records \n"; my $a_records = $zonefile->a(); foreach my $record (@$a_records) { print "$record->{name} resolves at $record->{host}\n"; } push (@$a_records, { name => 'new', class => 'IN', host => '127.0.0.7', ttl => '' }); $zonefile->new_serial(); my $soa = $zonefile->soa(); print "serial: ", $soa->{serial}, "\n", "origin: ", $soa->{origin}, "\n", "primary: ", $soa->{primary}, "\n", "refresh: ", $soa->{refresh}, "\n", "retry: ", $soa->{retry}, "\n", "ttl: ", $soa->{ttl}, "\n", "minimumTTL: ", $soa->{minimumTTL}, "\n", "email: ", $soa->{email}, "\n", "expire: ", $soa->{expire}, "\n"; push (@$soa, { refresh => '3600', retry => '600', ttl => '68400', mini +mumTTL => '1800'}); open NEWZONE, ">./zonefi.new" or die "error"; print NEWZONE $zonefile->output(); close NEWZONE;

edited by ybiC: s/pre/code/


In reply to Zone File manipulation by Bladernr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.