Here is a much more minimal example. Both times I tried this once without the extra purge() and once with. Both times memory was at 166MB after the dispose().
#!/usr/bin/perl -w
use strict;
use XML::Twig;
my $inFile = '../data/2009/data_verified/abms_dialogb_10000000_1009999
+9.xml';
if ( ! $inFile ) {
die("No input file specified");
}
if ( ! -f $inFile ) {
die("file '$inFile' not found");
}
process($inFile);
exit 0;
#
# Process the file
#
sub process {
$inFile =~ /data_(\d+)_(\d+)/;
my $t= new XML::Twig( TwigHandlers=> { BIOG => \&BIOG },
);
$t->parsefile( $inFile );
$t->purge(); # Will purge work?
$t->dispose(); # Try to Free memory but does not work...
}
#
# BIOG is XML element we are triggering
#
sub BIOG {
my ($t, $BIOG)= @_;
if ( ! checkBiog($BIOG->field('BIOG_NBR')) ) {
print "Missing ". $BIOG->field('BIOG_NBR') . "\n";
}
$t->purge(); # Tell XML::Twig to dispo of the rest of the tree we
+ don't care about
return 1;
}
#
# Check database for ID
#
sub checkBiog {
my ($biog) = @_;
return 1;
}
I will try to work on generating an example XML file. The current XML file is licensed data that I cannot share.
-
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.
|