Perhaps the following will offer some direction:
use strict; use warnings; my $directory = './zones'; my %zones = getZoneHash($directory); print "$_ -> $zones{$_}\n" for keys %zones; sub getZoneHash { my ($dir) = @_; my %hash; local $/; for my $file ( grep -f, <"$dir/*"> ) { open my $fh, '<', $file or die $!; my $data = <$fh>; close $fh; $hash{$1} = $2 if $data =~ /zone\s+"([^"]+)".+masters\s+{\s*([^}\s]+)\s*}/s +; } Kg return %hash; }
There are three files in the directory zones, and each contains only one of the following zone stanzas:
zone "zone.com" { type slave; file "path/to/db.zone"; masters {ip.add.ress.here}; }; zone "cnn.com" { type slave; file "path/to/db.zone"; masters { cnn.add.ress.here }; }; zone "perlmonks.org" { type slave; file "path/to/db.zone"; masters { ip.perlmonks.ress.here }; };
Output:
cnn.com -> cnn.add.ress.here perlmonks.org -> ip.perlmonks.ress.here zone.com -> ip.add.ress.here
The subroutine getZoneHash takes a directory parameter, and then opens, reads, and captures the zone info and masters ip address of the zone stanza in each file in that directory, building and returning a hash.
The capturing regex:
/zone\s+"([^"]+)".+masters\s+{\s*([^}\s]+)\s*}/s ^ ^ ^ ^ ^ ^ ^ ^ ^ | | | | | | | | | | | | | | | | | + - Treat string as sin +gle line | | | | | | | + - 0+ whitespaces | | | | | | + - Match anything that's not } o +r a whitespace | | | | | + - 0+ whitespaces | | | | + - 1+ whitespaces | | | + - End quotation | | + - Match anything that's not a " | + - Begin quotation + - 1+ whitespaces
Hope this helps!
In reply to Re: Bind zone file search
by Kenosis
in thread Bind zone file search
by ranceh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |