I have this program that uses XML::Parser. The Program runs fine up until the parse() function is called, and then something doesn't seem to work right. $hashref should be populated with data, but it is empty. I have checked and made sure that $xmldata contains the proper xml data. Does anybody have any ideas?
# LOAD MODULES
use XML::Parser;
use HTTP::Request;
use LWP::UserAgent;
use Net::FTP;
use strict;
# DEBUG VARIABLES
# set debug to 1 to enable debug mode, otherwise set to 0
my $debug = 1;
# enter file containing xml feed to use in debug mode
my $debug_xmlfilename = "feed.xml";
# ftp server to use in debug mode
my $debug_username = "somebody";
my $debug_password = "somewhere";
my $debug_ftpserver = "somehow";
# CUSTOM INFORMATION
my $froogle_username = "";
my $froogle_password = "";
my $froogle_ftpserver = "";
my $store_xmlfeed_url = "http://store.yahoo.com/storename/objinfo.xml";
# set to "Windows" or "Linux"; needed to find temp directory
my $operating_system = "Windows";
# DECLARE VARIABLES
my $xmlparser;
my $temp_directory;
my $froogle_data_filename;
my $xmldata; # string containing yahoo store xml data
my $user_agent;
my @redirectable_methods = (); # no methods should be redirectable
my $response;
my $fh_outfile; # file handle to the output file
my $filedata;
my @productarray;
my %product;
my $key;
my $hashref;
my $ftp;
# DEFINE XML PARSER SUBROUTINES
$xmlparser = new XML::Parser(Handlers => {
Start => \&tag_start,
End => \&tag_end,
Char => \&handle_char });
# INITIALIZE VARIABLES
if($debug) { print "Yahoo Store Export to Froogle - Debug.\n"; }
# figure out the temp directory path
if($operating_system eq "Windows")
{
$temp_directory = $ENV{TEMP}."\\";
}
if($operating_system eq "Linux")
{
$temp_directory = "/var/tmp/";
}
# set the filename for the temporary froogle data file
$froogle_data_filename = $temp_directory.$froogle_username.".txt";
if($debug)
{
print "Froogle data file name is: ";
print $froogle_data_filename."\n";
}
# open the file for output
open FH_OUTFILE, ">feedl.txt" or die ("Error opening file for write: $!");
# print column names
print FH_OUTFILE
"product_url\tname\tdescription\tprice\timage_url\tcategory\tcode\n";
# RETRIEVE THE ENTIRE XML FEED INTO A STRING
if (!$debug)
{
# create a user agent
$user_agent = LWP::UserAgent->new();
# disable redirection
$user_agent->requests_redirectable([EMAIL PROTECTED]);
# perform a get request
$response = $user_agent->get($store_xmlfeed_url);
# check the response
die ("Error while getting ".$response->request->uri.
"\nStatus-Line: ".$response->status_line."\nAborting")
unless ($response->is_success);
# copy the response data into a string
$xmldata = $response->content;
}
else
{
# read xml data from a debug file
open DEBUGXMLFILE, "<".$debug_xmlfilename;
while(read(DEBUGXMLFILE, $filedata, 10000))
{
$xmldata .= $filedata;
}
close DEBUGXMLFILE;
}
# RUN THE XML PARSER (PARSING IS DONE IN THE SUBROUTINES)
$xmlparser->parse($xmldata);
## Dies right around here ##
print "$hashref\n";
# WRITE THE PARSED DATA TO THE TEMP FILE
for $hashref (@productarray)
{
print FH_OUTFILE $hashref->{product_url}."\t";
print FH_OUTFILE $hashref->{name}."\t";
print FH_OUTFILE $hashref->{description}."\t";
print FH_OUTFILE $hashref->{price}."\t";
print FH_OUTFILE $hashref->{image_url}."\t";
print FH_OUTFILE $hashref->{category}."\t";
print FH_OUTFILE $hashref->{code};
print FH_OUTFILE "\n";
}
# debug print the parsed data
if(0)
{
for $hashref (@productarray)
{
print "\n\n";
for $key (keys %$hashref)
{
print "'$key' => '$hashref->{$key}' \n";
}
}
}
# close the output file
close (FH_OUTFILE);
if($debug)
{
$froogle_ftpserver = $debug_ftpserver;
$froogle_username = $debug_username;
$froogle_password = $debug_password;
}
"I'd take you seriously but to do so would be an affront to your intelligence."
-- William F. Buckley --
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
