http://www.perlmonks.org?node_id=344782

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

Greetings fellow monks I have a script that uses Net::DNS::ZoneFile & DBI to parse zone files and insert given records into my mySQL DB, but I have an issue that seems it might be memory related. When the script is ran it chugs along fine and then gets to a point and locks for what seems like forever ( 5 to 10 minutes also I see cpu usage at 98% or better when this happens ) now I think this may be due to it not clearing memory out, but am unsure. What I would like to do is make this script read 10 files dump the memory and then start from that stop point read the next 10 files and do the same till the end. I am not very sure of how to do this so I come to you for advice. code follows:
#!/usr/bin/perl use strict; use warnings; use File::Find; use FileHandle; use Net::DNS::ZoneFile; use DBI; my $dbh = DBI->connect( "DBI:mysql:database=dns;host=localhost", "root", "bla", {'RaiseError' => 1} ); my $sth = $dbh->prepare( "INSERT INTO a (hname,zone,host) VALUES (?,?,?)" ); my $base = "/chroot/named/master/net"; find(\&wanted, $base); $dbh->disconnect(); exit; sub wanted { return unless ( -f "$File::Find::name" and $File::Find::name !~ m! + /in-addr/! ); my $root = shift; my $zone = new FileHandle "$File::Find::name", "r"; my @name = split('/',$File::Find::name); my $out = join('.', reverse(@name[4..$#name])); my $rrset = Net::DNS::ZoneFile->readfh($zone, $root); for(@$rrset) { # print "$out\n"; # print "$_->{type}\n"; # print "$_->rdatastr\n" if $_->{type} =~ m/^A/; # print "$_->{name},",$_->rdatastr, "\n" if $_->{type} =~ m/^A/ +; if($_->{type} =~ m/^A/) { print "Working on file:\t$out\n"; $sth->execute( $_->{name}, $out, $_->rdatastr) or die $dbh-> +errstr; print "Finished work on file:\t$out\n"; } } }