Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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"; } } }

In reply to Clearing memory by sunadmn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (4)
    As of 2014-08-21 03:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (127 votes), past polls