Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Net::DNS::ZoneFile problem

by sunadmn (Curate)
on Jul 23, 2003 at 15:26 UTC ( [id://277204]=perlquestion: print w/replies, xml ) Need Help??

sunadmn has asked for the wisdom of the Perl Monks concerning the following question:

Good day all,
I have been trying for the last few days to get the PM Net::DNS::ZoneFile to work and am having some issues that I can not get around.
I was wondering if any of the monks have used this before or could help me with the specfic erros I am recieving. Following is my code and then the specfic errors I am recieving. Please forgive my ignorance as I am very new to the perl world.
#!/usr/bin/perl -w $| = 1; use strict; use File::Find; use FileHandle; use Net::DNS::ZoneFile; # use DNS::ZoneParse; use Data::Dumper; my $base = "/chroot/named/master/arpa/in-addr/68/168"; my $out_dir = "/var/tmp/ptr"; find(\&wanted, $base); exit; sub wanted { return unless ( -f "$File::Find::name" and $File::Find::name !~ m!/ +com/! ); return unless ( -f "$File::Find::name" and $File::Find::name !~ m!/ +net/! ); my $zone = $File::Find::name; my $out = join('.', ( split('/', $zone) )[-1,-2,-3]); my $rrset = Net::DNS::ZoneFile->readfh($zone[, $root]); # my $dns = DNS::ZoneParse->new("$zone"); open(OUT, ">$out_dir/$out") or die "Cant create $out_dir/$out: $!\n +"; print $_->string . "\n" for @$rrset; # print OUT Data::Dumper->Dump([$dns->ptr]) . "\n"; close(OUT); }
Error message:
[root@steve tmp] 738# perl -cwTM-strict ./ptr.pl Multidimensional syntax $zone[, $root] not supported at ./ptr.pl line +24. Global symbol "@zone" requires explicit package name at ./ptr.pl line +24. syntax error at ./ptr.pl line 24, near "[," Global symbol "$root" requires explicit package name at ./ptr.pl line +24. ./ptr.pl had compilation errors.

Replies are listed 'Best First'.
Re: Net::DNS::ZoneFile problem
by l2kashe (Deacon) on Jul 23, 2003 at 16:09 UTC

    About the error messages

    The errors about Global symbol <insert var here> are coming from the strict module. Any variable that you want to use must be declared in one of a few ways. Namely you can do

    use vars qw(@some $vars %in_here); # or you can do my %variable; # or even local $some_var;

    Each one has its own usage, and there are some gotchas. See your perl documentation about them

    The error Multidimensional syntax $zone, $root not supported at ./ptr.pl line 24. is stating that the syntax of your line simply is not correct. What you are handing the readfh method is a scalar and then an anonymous array with 2 elements the first being nothing and the second being $root (which is not shown in your code, so I assume doensn't exist).

    The documentation for that module isnt the best, but I will look over the source and see if I can't help out a touch more. Welcome to Perl :)


    Update:Ok so there were a few isues, and looking over the source here are the issues.

    #!/usr/bin/perl -w $| = 1; use strict; use File::Find; use FileHandle; use Net::DNS::ZoneFile; my $base = "/chroot/named/master/arpa/in-addr/68/168"; my $out_dir = "/var/tmp/ptr"; find(\&wanted, $base); exit; sub wanted { return unless ( -f "$File::Find::name" and $File::Find::name !~ m!/ +com/! ); return unless ( -f "$File::Find::name" and $File::Find::name !~ m!/ +net/! ); # Here we get the rootdir as an argument to the wanted function # then we are going to need to open it as a new filehandle # so that the module can read it. my $root = shift; my $zone = new FileHandle "$File::Find::name", "r"; my $out = join('.', ( split('/', $File::Find::name) )[-1,-2,-3]); my $rrset = Net::DNS::ZoneFile->readfh($zone, $root); # here you were printing to STDOUT, as opposed to OUT # which is what I assumed you wanted to do. open(OUT, ">$out_dir/$out") or die "Cant create $out_dir/$out: $!\n +"; print OUT $_->string . "\n" for @$rrset; close(OUT); }

    This code works. Mainly the issue was the $root var is an optional argument to the readfh method. If you didn't define it, then it used the current directory as the base directory to look for data in. So taking it as an arg for the wanted cleared it right up.

    Regards

    use perl;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://277204]
Approved by l2kashe
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found