|The stupid question is the question not asked|
Bind zone file searchby ranceh (Initiate)
|on Sep 26, 2012 at 01:13 UTC||Need Help??|
ranceh has asked for the
wisdom of the Perl Monks concerning the following question:
I have a directory full of bind dns zone files with hundreds of zone stanzas like:
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.