【发布时间】:2014-11-03 08:46:27
【问题描述】:
我正在使用 Perl 程序从一批 .htm 文件中提取文本,并将所有唯一的十字序列作为键存储在哈希中(最终结果是哈希,每个唯一的十字序列作为键和该序列作为值出现在所有文件中的次数)。
我的问题是代码继续提取 HTML 标记以及文本,尽管多次尝试使用诸如 HTML::Parser 之类的模块来摆脱 HTML。下面的代码不会产生错误消息,但它也没有摆脱 HTML 标记。有什么见解吗?
#!/usr/bin/perl
use strict;
use warnings;
package MyParser;
use base qw(HTML::Parser);
my $p = HTML::Parser->new;
my $path = "U:/Perl/risk disclosures";
chdir($path) or die "Cant chdir to $path $!";
# This program counts the total number of unique six-grams in a 10-K and enumerates the frequency of each one.
# Starting off computing a simple word count for each word in the 10-K.
my @sequence;
my %sequences;
my $fh;
# Here creating an array of ten-grams.
my @files = <*.htm>;
foreach my $file (@files) {
open( IFILE, $file );
while (<IFILE>) {
$p->parse($_);
for (split) {
push @sequence, $_;
if ( @sequence >= 10 ) {
shift @sequence until @sequence == 10;
++$sequences{"@sequence"};
}
}
}
}
close(IFILE);
【问题讨论】: