Front page | perl.beginners |
Postings from March 2002
Trouble with HTML::Parser
From:
Ron Goral
Date:
March 29, 2002 11:06
Subject:
Trouble with HTML::Parser
Message ID:
BNEHILDKCDOMHKMLNDCCAEDLCFAA.rongoral@uponthemountain.com
Would someone be kind enough to tell me why the code below does not work?
It is a library of sorts and resides in a file separate from the main cgi
(hence the "1;" at the end). It is activated with the call
&MapFormData($fileName). The print statements in MapFormData print to the
screen as I want and there are no errors either printed to the log file or
that kill the script. However, neither the procStart subroutine nor the
procEnd subroutine are invoked. I am not able to determine what the problem
is.
################## CODE SAMPLE FOLLOWS ##################
use strict;
use HTML::Parser;
use HTML::Entities qw(decode_entities);
require "dgcommon.cgi";
open(STDERR,">>dglogs/dgformapper.log")
or die("Could not open or create dgformapper.log: $!");
chmod 0666, "dglogs/dgformapper.log";
sub procStart
{
my ($tagname,$attr,$attrseq) = @_;
print qq[<b><i>$tagname -</i></b><br>];
for my $i(0..@$attrseq)
{
print qq[@$attrseq[$i] is %$attr->{@$attrseq[$i]}<br>];
}
} # end procStart
sub procEnd
{
my ($tagname) = @_;
print qq[End $tagname<br>==============================<br><br>];
} # end procEnd
sub MapFormData
{
my @formTags = qw(form input textarea button select option);
print qq[Entering MapFormData<br>];
my ($formUrl) = shift;
print qq[Just got $formUrl<br>];
open(FORMFILE,"$formUrl")?
print qq[Just opened $formUrl<br>]:
&LogEntry(\*STDERR,"dgformapper","MapFormData",
"Could not open $formUrl",$!);
my $p = HTML::Parser->new (api_version => 3,
start_h => [\&procStart, "tagname,attr,attrseq"],
end_h => [\&procEnd, "tagname"],
report_tags => [\@formTags ],
);
print qq[Created new HTML::Parser object<br>];
my $retVal = $p->parse_file(\*FORMFILE);
ref($retVal)?
print qq[Parsed the file<br>]:
&LogEntry(\*STDERR,"dgformapper","MapFormData",
"Could not parse file $formUrl",$!);
}
1;
################## END OF CODE SAMPLE ###################
Thanks in advance -
Peace In Christ -
Ron Goral
rongoral@uponthemountain.com <mailto:rongoral@uponthemountain.com>
-
Trouble with HTML::Parser
by Ron Goral