#!/usr/bin/perl
use strict;
use warnings;
my %hash;
my @vocabulary;
my $s1;
my $s2;
my $w;
my $one;
my $maxlen=8; #前向最大匹配的最大长度
my $filename;
my $dir="text";
open FILE1,"vocabulary.dic" || die "Cannot open file: $!"; #将文件打开
while (<FILE1>) { #将词表读入哈希
chomp;
@vocabulary=split / /; #因为我的词表中每个词前面都有个编号,所以要作这样的处理
$hash{$vocabulary[1]}='1';
}
opendir(DH,"$dir") || die "Cannot open $dir: $!"; #开启文件目录操作
foreach $filename (grep(/\.txt$/i,readdir DH)) { #依次读入文件目录中每个文件的内容
open FILE2,"<","$dir\\$filename" || die "Cannot open this file: $!"; #打开待切分的文本
open FILE3,">","out\\$filename" || die "Cannot open this file: $!"; #新建或打开作为输出结果的文本
while (<FILE2>) { #开始前向最大匹配
chomp($_);
$s1=$_;
$s1=~s/([\s\w\[\]\(\)\{\}\<\>\,\.\?\\\/\
|