Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Expat.pm and Parser.pm errors

by jpinones (Initiate)
on Oct 16, 2012 at 20:53 UTC ( #999423=perlquestion: print w/ replies, xml ) Need Help??
jpinones has asked for the wisdom of the Perl Monks concerning the following question:

I run my script and outputs:

Use of uninitialized value in subroutine entry at /usr/lib/perl5/XML/P +arser/Expat.pm line 475. no element found at line 1, column 0, byte -1 at /usr/lib/perl5/XML/Pa +rser.pm line 187

code is like this:

#!/usr/bin/perl -W use strict; use Archive::Zip; use Spreadsheet::ParseExcel; use Class::CSV; use Text::CSV; use Text::CSV_XS; use XML::Parser; use LWP::Simple; # used to fetch the chatterbox ticker die "You must provide a filename to $0 to be parsed as an Excel/Word f +ile" unless @ARGV; my $count; my $count2; my $count3; my $ARGV; my $d; my $b; my $a; my $c; my @array1 = ((undef),(undef)); my @array2 = ((undef),(undef)); my @array3 = ((undef),(undef)); my $string1; my $string2; my $message; # Hashref containing infos on a message my $oBook; my $cb_ticker; my $string0; if ($ARGV[$count] =~ "casoUso") { print "$count\n"; print "$ARGV[$count]\n"; $string0 = $ARGV[$count]; print "$string0\n"; print "mkdir $string0.dir\n"; ###gets the filename from the ARG given +from the command line run. system ("mkdir $string0.dir"); ###gets the filename from the ARG given + from the command line run. print "/usr/bin/unzip $ARGV[$count] -d ./$ARGV[$count].dir\n"; ###gets + the filename from the ARG given from the command line run. system ("/usr/bin/unzip $ARGV[$count] -d ./$ARGV[$count].dir"); ###get +s the filename from the ARG given from the command line run. $string1 = "./".$string0.".dir"."/word/document.xml"; print "$string1\n"; $cb_ticker = get("$string1"); print "paso cb ticker\n"; my $parser = new XML::Parser ( Handlers => { # Creates our parser obje +ct Start => \&hdl_start, End => \&hdl_end, Char => \&hdl_char, Default => \&hdl_def, }); print "paso parser\n"; $parser->parse($cb_ticker); print "paso parser2\n";

Any clue?

Comment on Expat.pm and Parser.pm errors
Select or Download Code
Re: Expat.pm and Parser.pm errors
by runrig (Abbot) on Oct 16, 2012 at 21:55 UTC
    If that's all your script prints then you have serious problems. You have a lot of print statements and very little output. But then I don't see any hdl_* subroutines so maybe that's your problem. Or maybe your input to one of the functions is not what you think it is. Or maybe there's a problem on line 42.

      I did not included all the IF but here is it

      if ($ARGV[$count] =~ "casoUso") { print "$count\n"; print "$ARGV[$count]\n"; $string0 = $ARGV[$count]; print "$string0\n"; print "mkdir $string0.dir\n"; ###gets the filename from the AR +G given from the command line run. system ("mkdir $string0.dir"); ###gets the filename from the A +RG given from the command line run. print "/usr/bin/unzip $ARGV[$count] -d ./$ARGV[$count].dir\n"; + ###gets the filename from the ARG given from the command line run. system ("/usr/bin/unzip $ARGV[$count] -d ./$ARGV[$count].dir") +; ###gets the filename from the ARG given from the command line run. $string1 = "./".$string0.".dir"."/word/document.xml"; print "$string1\n"; # print "$count\n"; # print "$ARGV[$count]\n"; # system ("mkdir ($ARGV[$count].dir)"); ###gets the filename fr +om the ARG given from the command line run. # system ("'/usr/bin/unzip' '$ARGV[$count]' -d './$ARGV[$count] +.dir'"); ###gets the filename from the ARG given from the command lin +e run. # use XML::Parser; # use LWP::Simple; # used to fetch the chatterbox ticker $cb_ticker = get("$string1"); # $cb_ticker = exec ("cat $string1"); print "paso cb ticker\n"; my $parser = new XML::Parser ( Handlers => { # Creates our p +arser object Start => \&hdl_start, End => \&hdl_end, Char => \&hdl_char, Default => \&hdl_def, }); print "paso parser\n"; $parser->parse($cb_ticker); print "paso parser2\n"; # The Handlers sub hdl_start{ my ($p, $elt, %atts) = @_; return unless $elt =~ m/'RF'/; # We're only interrested i +n what's said $atts{'_str'} = ''; $message = \%atts; for ($count = 1; $count <= $ARGV[4]; $count++) { if (($message =~ "CU$count ,") or ($message =~ "CU$count," +)) { for ($count2 = 1; $count2 <= $ARGV[4]; $count2++) { if (($array2[$count][1] =~ "RF$count.$count2 ") or + ($array2[$count][1] =~ "RF$count.$count2,") or ($array2[$count][1] = +~ "RF $count.$count2,") or ($array2[$count][1] =~ "RF $count.$count2 +,")) { $array2[$count][2]=$message; ### captures RF n +umber to array } } } } } sub hdl_end{ my ($p, $elt) = @_; format_message($message) if $elt =~ m/'CU'/ && $message && + $message->{'_str'} =~ /\S/; } sub hdl_char { my ($p, $str) = @_; $message->{'_str'} .= $str; } sub hdl_def { } # We just throw everything else sub format_message { # Helper sub to nicely format what we got + from the XML my $atts = shift; $atts->{'_str'} =~ s/\n//g; my ($y,$m,$d,$h,$n,$s) = $atts->{'time'} =~ m/^(\d{4})(\d{ +2})(\d{2})(\d{2})(\d{2})(\d{2})$/; # Handles the /me $atts->{'_str'} = $atts->{'_str'} =~ s/^\/me// ? "$atts->{'author'} $atts->{'_str'}" : "<$atts->{'author'}>: $atts->{'_str'}"; $atts->{'_str'} = "$h:$n " . $atts->{'_str'}; print "$atts->{'_str'}\n"; undef $message; } }
        It is best to post as little code as possible that actually runs (and that anyone can run) and demonstrates your problem (stating the output you got and the output you expected). Again, "as little code as possible, that runs as a standalone test case". Do you have a small test case? Often, by the time you cut it down to a small test case, you've solved your problem.
Re: Expat.pm and Parser.pm errors
by brap (Pilgrim) on Oct 17, 2012 at 12:25 UTC

    Hi jpinones,

    Not to detract from runrig's debugging advice, but I wonder if you've checked the value of $cb_ticker right before the $parser->parse($cb_ticker); call? Just a hunch, but I have a feeling it might not contain what it should.

      I tried to do that with a single print but does not work either. How can I check the containing stuff?

        Hi jpinones,

        Back to runrig's first reply, is the output from your original message the only output you're getting, or are other things showing up? I'd hope you're seeing the 'mkdir' and 'unzip' lines at least, in addition to the errors you provided.

        Based on what's at LWP::Simple, the get() method can return undef if it fails. I'm not clear on what you mean by "does not work either" -- maybe it's not displaying anything? What if you try print "cb_ticker: [$cb_ticker]\n"; and see what shows up between the brackets?

        You do appear to be displaying the value of $string1, which is what you're trying to retrieve - have you ensured that value is what you expect (I would guess you have, but can't hurt much to ask)?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://999423]
Approved by rovf
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2014-09-21 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (172 votes), past polls