I hereby suggest that you, masterGaurav post some sample HTML and you,
robic0 give us a sample script which demonstrates the use of your
crummy parser to parse it.
and robic, don't give us any bullshit about how expensive your time is
and you can't afford to show a sample, a solid product demonstration
will pay for itself 10-fold.
with bated breath,
-jp
Hey thats fair. The RXParse code (on this forum) needs to have the top usage examples,
before the package declaration, commented out and a "1;" added to before the __END__.
Add a 'strict' statement after the package name. The file should be namee RXParse.pm.
Using Todd W's data sample within this thread, just using the default handlers with debug off
(turning debug off just does syntax checking) yeilds this nice error:
======================================================
use strict;
use warnings;
use RXParse;
my $parse_ln = '
<html>
<head>
<title>$100.00 Dollars</title>
</head>
<body>
<img src="foo.img" alt="$100.00 USD">
<div>size: 50 x 50</div>
<div>discount: $75.25</div>
</body>
</html>
';
my $p = new RXParse();
#$p->setDebugMode(1);
$p->parse(\$parse_ln);
__END__
rp_error_05, expected closing tag '/img' (line 10, col 9)
==========================================================
There, now that didn't take alot of my time.
Un-commenting the debug line above yeilds this:
SCALAR ref
--------------------
char _:
--------------------
start _: html
--------------------
char _:
--------------------
start _: head
--------------------
char _:
--------------------
start _: title
--------------------
char _: $100.00 Dollars
--------------------
end _: /title
--------------------
char _:
--------------------
end _: /head
--------------------
char _:
--------------------
start _: body
--------------------
char _:
--------------------
start _: img
src = foo.img
alt = $100.00 USD
--------------------
char _:
--------------------
start _: div
--------------------
char _: size: 50 x 50
--------------------
end _: /div
--------------------
char _:
--------------------
start _: div
--------------------
char _: discount: $75.25
--------------------
end _: /div
--------------------
char _:
--------------------
rp_error_05, expected closing tag '/img' (line 10, col 9)
=============================================================
You can expect the same data to be passed to your user defined handlers.
The code that sets the user defined handlers goes like this:
sub setHandlers {
my ($self, @args) = @_;
my %oldh = ();
if (!scalar(@args)) {
while (my ($name,$val) = splice (@args, 0, 2)) {
$name =~ s/^\s+//s; $name =~ s/\s+$//s;
my $hname = "h".lc($name);
if (exists $self->{$hname}) {
$oldh{$name} = $self->{$hname};
if (ref($val) eq 'CODE') {
$self->{$hname} = $val;
} else {
# if its not a CODE ref,
# just set default handler
$self->setDfltHandlers ($name);
}
}
}
}
return %oldh;
}
I'll make up a sample user friendly template for you in a little bit.
The parameters passed to the handlers, as well as setting the handlers
are those typical Expat, mostly. There are many ways this can parse a block.
See the parse method. I wouldn't be so quick to call this a 'crappy' parser boy!
robic0