I have tried doing this in a little practise program, and I am still getting stuck.
Please forgive my Perl newb-dom.
Here is the error I am getting, and it doesn't really make too much sense to me, given that I am not constructing a new ShimPractise on that line:
[Sun Aug 30 10:30:50 2009] [error] [client 127.0.0.1] Premature end of script headers: SBG_ReceivedMessageListener.pl
[Sun Aug 30 10:30:50 2009] [error] [client 127.0.0.1]
Not enough arguments for ShimPractise::new at ShimPractise.pm line 26, near ");"\r
[Sun Aug 30 10:30:50 2009] [error] [client 127.0.0.1] Compilation failed in require at SBG_InitiateRetrieveLoggedEventDataRequestHandler.pm line 8.\r
[Sun Aug 30 10:30:50 2009] [error] [client 127.0.0.1] BEGIN failed--compilation aborted at SBG_InitiateRetrieveLoggedEventDataRequestHandler.pm line 8.\r
[Sun Aug 30 10:30:50 2009] [error] [client 127.0.0.1] Compilation failed in require at C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/SBG_ReceivedMessageListener.pl line 5.\r
[Sun Aug 30 10:30:50 2009] [error] [client 127.0.0.1] BEGIN failed--compilation aborted at C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/SBG_ReceivedMessageListener.pl line 5.\r
And here is the code:
First the ShimPractise.pm module:
#!/perl/bin/perl
#Practise shim form of xml parsing.
package ShimPractise;
use strict;
use XML::Parser;
sub new ($$$)
{
my $shimClass = $_[0];
my $shimData = {
name => $_[1],
number => $_[2],
xmlAsScalar => $_[3],
};
bless ($shimData, $shimClass);
return $shimData;
}
sub parse()
{
my ($currentObject) = @_;
my $parser = new XMLParser(Handlers
=> { Init => sub {$currentObject->handleDocumentInit (@_)},
Start => sub {$currentObject->handleStartTag (@_)},});
$parser->parse($currentObject->{xmlAsScalar});
my $returnString = "";
my $numTags = $currentObject->getNumber();
$returnString .= "Number of Tags: ".$numTags."<BR>\n";
my $tags = $currentObject->getName();
$returnString .= $tags."<BR>\n";
return $returnString;
}
sub setName($)
{
$_[0]->{name} = $_[1];
}
sub setNumber($)
{
$_[0]->{number} = $_[1];
}
sub getName()
{
return $_[0]->{name};
}
sub getNumber()
{
return $_[0]->{number};
}
sub handleDocumentInit()
{
my ($currentObject, $expat) = @_;
$currentObject->setName("Tags: ");
$currentObject->setNumber(0);
}
sub handleStartTag()
{
my ($currentObject, $expat, $element, %attrList) = @_;
my $currentName = $currentObject->getName();
my $currentNumber = $currentObject->getNumber();
$currentObject->setName($currentName." ".$element);
$currentObject->setNumber($currentNumber + 1);
}
1;
And now the code I use to call it:
my $shimmer = new ShimPractise("name", 0, "<Tag1><Tag2></Tag2><Tag3>
+</Tag3></Tag1>");
my $shimString = $shimmer->parse();
Any idea why this gives me such a confusing error message? Is the XML::Parser trying to construct a new instance of ShimPractise when it calls the handleStartTag function?
Any help is much appreciated, cheers,
Shug
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.