Hi, ranceh
Am using v5.16, but there's nothing in the code that would prevent its execution by much earlier versions, so I suspect the issue is something else. Try the following change to the subroutine:
use strict; use warnings; my $directory = './zones'; my %zones = getZoneHash($directory); print "$_ -> $zones{$_}\n" for keys %zones; sub getZoneHash { my ($dir) = @_; my %hash; my @files = grep -f, <"$dir/*"> or die "Problem getting filenames in $dir/: $!"; local $/; for my $file (@files) { open my $fh, '<', $file or die $!; my $data = <$fh>; close $fh; $hash{$1} = $2 if $data =~ /zone\s+"([^"]+)".+masters\s+{\s*([^}\s]+)\s*}/s +; } return %hash; }
Now there's a check for file names being read from the desired directory. The script will die with a message if none were read.
If you're still getting the same results, temporarily place the following just below the close $fh; line:
print $data; exit;
You should see a zone stanza that the regex would process. If not, the next step would be to figure out why the file contents are not being read into $data.
In reply to Re^3: Bind zone file search
by Kenosis
in thread Bind zone file search
by ranceh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |