Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I have a directory full of bind dns zone files with hundreds of zone stanzas like:

zone "zone.com" { type slave; file "path/to/db.zone"; masters { ip.add.ress.here }; };

There is some variation in the stanzas wrt the line spacing around the masters directive. Sometimes the ip address is on a line by itself under the open brace.

I have part of a perl script that has built an array of zone file names, and an array of zone names from these zone files.

Now I need to find the master ip for each zone in the zone array but I have no idea which zone file it came from.

I'm thinking nested foreach or while loops over the zone names and zone files arrays.

The end result should be a hash with the zones as key names and the master ip as the value.

My data is consistent in that there are only two variations of line spacing in all the zone files I have.

I specifically don't understand how to write the regex for this case given the variation in line spacing to place in the map function to return the ip address. I also don't have a feel for the most efficient way to loop through the zone names and files stopping when I find a match, because there will be only one match in the set of files.

I know from reading docs and googling that I need a multiline grep and that I need to unset $/ and read the whole zone file into a temp variable, but that's where I stopped understanding.

I would appreciate any hints, insights and pointers you may have.


In reply to Bind zone file search by ranceh

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2014-08-23 00:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (168 votes), past polls