首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译perl脚本时的错误和奇怪行为

编译perl脚本时的错误和奇怪行为
EN

Stack Overflow用户
提问于 2014-10-29 11:30:11
回答 1查看 866关注 0票数 1

我有一个perl脚本,当我用perl2exe编译它时,它会给出以下消息:

Can't locate unicore/Heavy.pl in @INC (@INC contains: PERL2EXE_STORAGE c:\tools\hunalign\scripts\sentence_splitter C:\Users\EURIDE~1\AppData\Local\Temp/p2xtmp-5936) at PERL2EXE_STORAGE/utf8_heavy.pl line 176.

我有独角兽模块中的文件,所以我不知道问题出在哪里。但是,我可以通过插入以下行来暂时克服这一问题:

代码语言:javascript
复制
#perl2exe_include "unicore/Heavy.pl";

现在它没有错误地编译,但是exe的工作方式与程序创建者编译的原始exe略有不同。(这是一个解析器,它可以对句子进行分段,而我的exe不会在句号处进行切分)。这可能是由于perl2exe免费版本的限制吗?有什么想法吗?

代码(用于原始构建和我自己的)

代码语言:javascript
复制
#!/usr/bin/perl -w

use Encode::Unicode;
use utf8;
#perl2exe_include "unicore/Heavy.pl";

# Based on Preprocessor written by Philipp Koehn

binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");

use FindBin qw($Bin);
use strict;

my $mydir = "$Bin/nonbreaking_prefixes";

my %NONBREAKING_PREFIX = ();
my $language = "en";
my $QUIET = 0;
my $HELP = 0;

while (@ARGV) {
    $_ = shift;
    /^-l$/ && ($language = shift, next);
    /^-q$/ && ($QUIET = 1, next);
    /^-h$/ && ($HELP = 1, next);
}

if ($HELP) {
    print "Usage ./split-sentences.perl (-l [en|de|...]) < textfile > splitfile\n";
    exit;
}
if (!$QUIET) {
    print STDERR "Sentence Splitter v3\n";
    print STDERR "Language: $language\n";
}

my $prefixfile = "$mydir/nonbreaking_prefix.$language";

#default back to English if we don't have a language-specific prefix file
if (!(-e $prefixfile)) {
    $prefixfile = "$mydir/nonbreaking_prefix.en";
    print STDERR "WARNING: No known abbreviations for language '$language', attempting fall-back to English version...\n";
    die ("ERROR: No abbreviations files found in $mydir\n") unless (-e $prefixfile);
}

if (-e "$prefixfile") {
    open(PREFIX, "<:utf8", "$prefixfile");
    while (<PREFIX>) {
        my $item = $_;
        chomp($item);
        if (($item) && (substr($item,0,1) ne "#")) {
            if ($item =~ /(.*)[\s]+(\#NUMERIC_ONLY\#)/) {
                $NONBREAKING_PREFIX{$1} = 2;
            } else {
                $NONBREAKING_PREFIX{$item} = 1;
            }
        }
    }
    close(PREFIX);
}

##loop text, add lines together until we get a blank line or a <p>
my $text = "";
while(<STDIN>) {
    chop;
    if (/^<.+>$/ || /^\s*$/) {
        #time to process this block, we've hit a blank or <p>
        &do_it_for($text,$_);
        print "<P>\n" if (/^\s*$/ && $text); ##if we have text followed by <P>
        $text = "";
    }
    else {
        #append the text, with a space
        $text .= $_. " ";
    }
}
#do the leftover text
&do_it_for($text,"") if $text;


sub do_it_for {
    my($text,$markup) = @_;
    print &preprocess($text) if $text;
    print "$markup\n" if ($markup =~ /^<.+>$/);
    #chop($text);
}

sub preprocess {
    # clean up spaces at head and tail of each line as well as any double-spacing
    $text =~ s/ +/ /g;
    $text =~ s/\n /\n/g;
    $text =~ s/ \n/\n/g;
    $text =~ s/^ //g;
    $text =~ s/ $//g;

    #this is one paragraph
    my($text) = @_;

    #####add sentence breaks as needed#####

    #non-period end of sentence markers (?!) followed by sentence starters.
    $text =~ s/([?!]) +([\'\"\(\[\¿\¡\p{IsPi}]*[\p{IsUpper}])/$1\n$2/g;

    #multi-dots followed by sentence starters
    $text =~ s/(\.[\.]+) +([\'\"\(\[\¿\¡\p{IsPi}]*[\p{IsUpper}])/$1\n$2/g;

    # add breaks for sentences that end with some sort of punctuation inside a quote or parenthetical and are followed by a possible sentence starter punctuation and upper case
    $text =~ s/([?!\.][\ ]*[\'\"\)\]\p{IsPf}]+) +([\'\"\(\[\¿\¡\p{IsPi}]*[\ ]*[\p{IsUpper}])/$1\n$2/g;

    # add breaks for sentences that end with some sort of punctuation are followed by a sentence starter punctuation and upper case
    $text =~ s/([?!\.]) +([\'\"\(\[\¿\¡\p{IsPi}]+[\ ]*[\p{IsUpper}])/$1\n$2/g;

    # special punctuation cases are covered. Check all remaining periods.
    my $word;
    my $i;
    my @words = split(/ /,$text);
    $text = "";
    for ($i=0;$i<(scalar(@words)-1);$i++) {
        if ($words[$i] =~ /([\p{IsAlnum}\.\-]*)([\'\"\)\]\%\p{IsPf}]*)(\.+)$/) {
            #check if $1 is a known honorific and $2 is empty, never break
            my $prefix = $1;
            my $starting_punct = $2;
            if($prefix && $NONBREAKING_PREFIX{$prefix} && $NONBREAKING_PREFIX{$prefix} == 1 && !$starting_punct) {
                #not breaking;
            } elsif ($words[$i] =~ /(\.)[\p{IsUpper}\-]+(\.+)$/) {
                #not breaking - upper case acronym  
            } elsif($words[$i+1] =~ /^([ ]*[\'\"\(\[\¿\¡\p{IsPi}]*[ ]*[\p{IsUpper}0-9])/) {
                #the next word has a bunch of initial quotes, maybe a space, then either upper case or a number
                $words[$i] = $words[$i]."\n" unless ($prefix && $NONBREAKING_PREFIX{$prefix} && $NONBREAKING_PREFIX{$prefix} == 2 && !$starting_punct && ($words[$i+1] =~ /^[0-9]+/));
                #we always add a return for these unless we have a numeric non-breaker and a number start
            }

        }
        $text = $text.$words[$i]." ";
    }

    #we stopped one token from the end to allow for easy look-ahead. Append it now.
    $text = $text.$words[$i];

    # clean up spaces at head and tail of each line as well as any double-spacing
    $text =~ s/ +/ /g;
    $text =~ s/\n /\n/g;
    $text =~ s/ \n/\n/g;
    $text =~ s/^ //g;
    $text =~ s/ $//g;

    #add trailing break
    $text .= "\n" unless $text =~ /\n$/;

    return $text;

}
EN

回答 1

Stack Overflow用户

发布于 2014-10-29 11:40:21

无法在@INC中找到XYZ意味着Perl无法在@INC中找到XYZ模块。这意味着要么模块未安装,要么其路径不可搜索,您需要将该路径添加到@INC。

请参阅以下线程:

  1. Perl的@INC是如何构造的?(也就是影响在何处搜索Perl模块的所有方法?)
  2. 如何更改@INC以在非标准位置找到Perl模块

使用#perl2exe_include "unicore/Heavy.pl";解决了这个问题,因为它指定了模块的路径,因此Perl知道在哪里查找。(perl2exe将模块添加到可执行文件中)。

exe的工作方式与原来的exe稍有不同。

你应该分享你的代码,否则我们怎么知道什么是原始的和什么是当前的?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26629209

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档