The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Net::DNS::ZoneFile - Perl extension to convert a zone file to a collection of RRs


  use Net::DNS::ZoneFile;

  my $rrset = Net::DNS::ZoneFile->read($filename[, $root]);

  print $_->string . "\n" for @$rrset;

  my $rrset = Net::DNS::ZoneFile->readfh($fh[, $root]);

  # OR

  my $rrset = Net::DNS::ZoneFile->parse($ref_to_myzonefiletext[, $root]);


This module parses a zone file and returns a reference to an array of Net::DNS::RR objects containing each of the RRs given in the zone in the case that the whole zone file was succesfully parsed. Otherwise, undef is returned.

The zone file can be specified as a filename, using the ->read() method, or as a file handle, using the ->readfh() method. If you already have a scalar with the contents of your zone file, the most efficient way to parse it is by passing a reference to it to the ->parse() method.

The optional $root parameter, tells the module where to anchor $INCLUDE statements found in the zone data. It defaults to the current directory.

In case of error, undef will be returned.

The primitives $ORIGIN and $GENERATE are understood automatically.

Note that the text passed to ->parse() by reference, is copied inside the function to avoid modifying the original text. If this is not an issue, you can use ->_parse() instead, which will happily spare the performance penalty AND modify the input text.


None by default.



Original version; created by h2xs with options


This is actually, the second version. The first was trying to use Parse::RecDescent, but the result was a piece of code much more complex than what was really needed. This made me switch the implementation to the current regexp engine, which provide faster and more maintainable code.


Calin Medianu pointed out that @ can be in the RHS. New tests were written to this end and the code modified to treat this case in a manner consistent with BIND/named. This version was not distributed by mistake.


Anton Berezin provided patches for some short-sighted assumptions and bugs. Reduced the strictness of the whitespace requirements for parsing SOA RRs.


Added support for a reentrant $INCLUDE. Funs Kessen added support for AAAA and HINFO.


Funs Kessen submitted patches to make this module behave more like BIND.


Release of 1.03_1 as stable.


Luis E. Munoz <>