I am trying to put xml data into mysql using perl

I have:
-------------------
#!/usr/bin/perl -w
use strict;
use DBI;
use XML::Parser;

#create hash to hold values for expected column names
my %row = ("name" => undef, "category" => undef);

#connect to database
my $dsn = "DBI:mysql:database=tester;host=localhost";
my $dbh = DBI->connect ($dsn, 'user', 'password',
                     {RaiseError => 1}) ||
die $DBI::errstr;

#create parser object
my $parser = new XML::Parser (
         Handlers => 
            {
                              Start => \&handle_start,
                              End   => \&handle_end,
                              Char  => \&handle_text
            }
         );

#parse file and disconnect
$parser->parsefile ("data.xml");
$dbh->disconnect ();
-------------------

The xml file:
-------------------
<?xml version="1.0" encoding="UTF-8"?>
   <database>
    <select query="SELECT name, category FROM animal">
     <row>
      <name>snake</name>
      <category>reptile</category>
     </row>
     <row>
      <name>frog</name>
      <category>amphibian</category>
     </row>
     <row>
      <name>tuna</name>
      <category>fish</category>
     </row>
     <row>
      <name>racoon</name>
      <category>mammal</category>
     </row>
    </select>
   </database>
-------------------
The error:

Undefined subroutine &main::handle_start called at 
/Library/Perl/5.8.6/darwin-thread-multi-2level/XML/Parser/Expat.pm line 
469.

Perl is 5.8.6

I am open to other methods xml needs to go into mysql. Intermediate 
method is open trying perl I am new to perl. I am trying to take about 
100 xml files 50 pages each and get them into mysql. I want this to be 
automated as this will occur every month so. Started with basic example 
above.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to