Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2024-04-16 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found