我收到了错误
Undefined subroutine &main::1 called at /usr/local/lib/perl/5.10.0/HTML/Parser.pm line 102.
Run Code Online (Sandbox Code Playgroud)
这是我的代码
#open (IN, "<", "foo.html") or die "can't open source file: $!";
my $p = HTML::Parser->new( api_version => 3,
start_h => [&start, "tagname, attr, text"],
text_h => [&text, "text"],
default_h => [sub { print OUT shift }, "text"],
);
$p->utf8_mode;
$p->empty_element_tags;
$p->ignore_elements(qw(br));
$p->parse_file("foo.html") or die "parsing failed: $!";
#while (<IN>) {
# $p->parse($_) || die "parsing failed: $!";
#}
#$p->eof;
#close IN;
Run Code Online (Sandbox Code Playgroud)
正如你在注释掉的部分中看到的那样,我也尝试直接打开并调用解析(同样运气不大).
该文件确实打开.
Parser.pm第102行是错误提及的是parse_file子例程,特别是调用行 - >解析
我不知道parse在哪里,它不在HTML :: Parser中,也没有在HTML :: …