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

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 "" { type slave; file "path/to/"; masters { }; };

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

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, 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
  • 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (4)
    As of 2020-01-27 08:34 GMT
    Find Nodes?
      Voting Booth?