Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Bind zone file search

by ranceh (Initiate)
on Sep 26, 2012 at 14:53 UTC ( #995791=note: print w/ replies, xml ) Need Help??


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

What version of perl did you use?

This code does not generate any errors, but does not generate output.


Comment on Re^2: Bind zone file search
Re^3: Bind zone file search
by Kenosis (Priest) on Sep 26, 2012 at 16:21 UTC

    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.

      I think I found the problem.

      I modified your regex slightly in the beginning it starts with "/^zone..."

      I found after posing this question last night that a few of the zone files have stanzas commented out.

      The ^ in combination with the change to $/ seem to conflict with each other.

      I think it would be easier to add a not part to the regex before zone so that what is before zone is not a comment character identifier.

        Ah, good! Do you have an example of the commented-out stanzas? I suspect the regex can be modified to manage these exceptions.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995791]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2014-07-30 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (236 votes), past polls