我收到錯誤Perl HTML ::解析器錯誤;未定義子程序及主要:: 1
Undefined subroutine &main::1 called at /usr/local/lib/perl/5.10.0/HTML/Parser.pm line 102.
這裏是我的代碼
#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;
正如你可以在註釋部分我還試圖直接打開並調用解析看(同樣運氣不多)。
該文件打開正常。
Parser.pm線102這是錯誤中提到的是parse_file子程序,特別是排隊叫號 - >解析
我不知道在那裏分析是,它不是在HTML解析器::也沒有我發現它在HTML :: Entities中,唯一的依賴HTML :: Parser具有。 = /恐怕我在這一點上迷失了,PERL最深的魔法對我來說仍然是個謎。
你使用'use strict;使用警告;'? – TLP
fwiw,method'parse'顯然是一個XS例程(即它在C中實現) – ErikR