G
GlenM
Hi;
I was hoping someone could help me shed some light on this.
I have a Perl script, which I will post the contents below. It seems to get 'stuck' and I have to do an actually kill of the process.
I ran it using the Perl debugger (perl -d <script.pl>) and it seems to slow right down when reading back the array.
However, it does work - it does populate the database with the XML files as it is supposed to - so, that much I know.
So, any assistance I can get. I would much appreciate the help.
++++++++++++++++++++++++++++++
#!/usr/bin/perl
#use strict;
use DBI;
use XML::XPath;
use XML::XPath::XMLParser;
# Set the input dir where all of the XML files live
my $input_dir = ".";
# Begin reading the directory
opendir(DIR, $input_dir) || die "sorry shit the bed $input_dir: $!";
# Read them into an array
my @files_in_dir = grep { /xml/ } readdir(DIR);
closedir DIR;
# connect to database and create parser object
my $dbh = DBI->connect ("DBI:mysql:can_us_ratecenters",
"xxxxx", "xxxxxxx",
{ RaiseError => 1, PrintError => 0});
# clear the database - new DIDs coming in
$dbh->do ('TRUNCATE TABLE rc_city_town');
#Now the fun begins - read each file and put it in the database
foreach my $f (@files_in_dir) {
open IN, "<$f";
my $xp = XML::XPath->new (filename => "./$f");
my $nodelist = $xp->find ("//row");
foreach my $row ($nodelist->get_nodelist ())
{
$dbh->do (
"INSERT IGNORE INTO rc_city_town (state_prov, city_town, did_number) VALUES (?,?,?)",
undef,
$row->find ("state")->string_value (),
$row->find ("ratecenter")->string_value (),
$row->find ("number")->string_value (),
);
}
close IN;
}
$dbh->disconnect ();
++++++++++++++++++++++++++++++++++++++++++++==
I was hoping someone could help me shed some light on this.
I have a Perl script, which I will post the contents below. It seems to get 'stuck' and I have to do an actually kill of the process.
I ran it using the Perl debugger (perl -d <script.pl>) and it seems to slow right down when reading back the array.
However, it does work - it does populate the database with the XML files as it is supposed to - so, that much I know.
So, any assistance I can get. I would much appreciate the help.
++++++++++++++++++++++++++++++
#!/usr/bin/perl
#use strict;
use DBI;
use XML::XPath;
use XML::XPath::XMLParser;
# Set the input dir where all of the XML files live
my $input_dir = ".";
# Begin reading the directory
opendir(DIR, $input_dir) || die "sorry shit the bed $input_dir: $!";
# Read them into an array
my @files_in_dir = grep { /xml/ } readdir(DIR);
closedir DIR;
# connect to database and create parser object
my $dbh = DBI->connect ("DBI:mysql:can_us_ratecenters",
"xxxxx", "xxxxxxx",
{ RaiseError => 1, PrintError => 0});
# clear the database - new DIDs coming in
$dbh->do ('TRUNCATE TABLE rc_city_town');
#Now the fun begins - read each file and put it in the database
foreach my $f (@files_in_dir) {
open IN, "<$f";
my $xp = XML::XPath->new (filename => "./$f");
my $nodelist = $xp->find ("//row");
foreach my $row ($nodelist->get_nodelist ())
{
$dbh->do (
"INSERT IGNORE INTO rc_city_town (state_prov, city_town, did_number) VALUES (?,?,?)",
undef,
$row->find ("state")->string_value (),
$row->find ("ratecenter")->string_value (),
$row->find ("number")->string_value (),
);
}
close IN;
}
$dbh->disconnect ();
++++++++++++++++++++++++++++++++++++++++++++==