http://www.perlmonks.org?node_id=995860


in reply to Re^8: Bind zone file search
in thread Bind zone file search

You're very welcome, ranceh!

Replies are listed 'Best First'.
Re^10: Bind zone file search
by ranceh (Novice) on Sep 26, 2012 at 20:15 UTC

    I've been testing this for the last little bit and I think I found something else.

    It wont match more than one entry per zone file. But there are more stanzas in each zone file.

    When I googled this, I see that I should change the trailing end of a regex to /m for multiple matches, but when I do, I don't get any. What am I missing?

      The m modifier will not help here. I (incorrectly) assumed that there was only one zone stanza per file. Processing multiple zone stanzas requires globally matching and preventing part of the regex from being 'greedy.' Try the following line:

      $hash{$1} = $2 while $data =~ /zone\s+"([^"]+)".+?masters\s+{[\s#\/]*([a-zA-Z0-9.- +]+)[\s#\/;]*}/sg;

      You'll note that: while has replaced if, there's a ? right after the + preceding masters, and the globally modifier is used.

      while is used to process all matches; the ? prevents the regex from being 'greedy,' so it doesn't start the match at the beginning of a zone stanza and end the match with the last stanza.

        This is really close, but not quite right.

        This regex is matching commented zone directives and if the comment is found after the real one is overwriting good answers for bad ones.

        I need to avoid commented stanzas. Since commented stanzas include comment characters prior to the match of zone, I think I need a way to ensure that matches on the word zone. Am I thinking correctly?