-CSD太晚了

时间:2012-03-20 02:25:01

标签: perl

尝试从parsCit运行这个小的perl程序:

  

parsCit-client.pl e1.txt   [filename]第1行的-CSD选项太迟了

e1.txt在这里:http://dl.dropbox.com/u/10557283/parserProj/e1.txt

我从win7 cmd运行程序,而不是Cygwin。

filename是parsCit-client.pl - 整个程序在这里:

#!/usr/bin/perl -CSD
#
# Simple SOAP client for the ParsCit web service.
#
# Isaac Councill, 07/24/07
#
use strict;
use encoding 'utf8';
use utf8;
use SOAP::Lite +trace=>'debug';
use MIME::Base64;
use FindBin;

my $textFile = $ARGV[0];
my $repositoryID = $ARGV[1];

if (!defined $textFile || !defined $repositoryID) {
    print "Usage: $0 textFile repositoryID\n".
    "Specify \"LOCAL\" as repository if using local file system.\n";
    exit;
}

my $wsdl = "$FindBin::Bin/../wsdl/ParsCit.wsdl";

my $parsCitService = SOAP::Lite
    ->service("file:$wsdl")
    ->on_fault(
           sub {
           my($soap, $res) = @_;
           die ref $res ? $res->faultstring :
               $soap->transport->status;
           });

my ($citations, $citeFile, $bodyFile) =
    $parsCitService->extractCitations($textFile, $repositoryID);

#print "$citations\n";
#print "CITEFILE: $citeFile\n";
#print "BODYFILE: $bodyFile\n";

2 个答案:

答案 0 :(得分:8)

来自perldoc perlrun,关于-C开关:

  

注意:从perl 5.10.1开始,如果在“#!”上使用-C选项行,它   必须在命令行上指定,因为标准   在执行perl时此时已经设置了流   翻译。您还可以使用binmode()来设置I / O的编码   流。

这可能是编译器所说的“为时已晚”。

换句话说:

perl -CSD parsCit-client.pl 

答案 1 :(得分:2)

因为#!" shebang"中的命令行选项并没有在所有操作系统中一致地传递(参见this answer),并且Perl在解析脚本shebang之前已经打开了流,因此在一些较旧的操作系统中无法弥补这一点,因此在bug 34087中决定在shebang中禁止-C。当然,并非所有人都对此感到满意,特别是如果它本来可以在他们的操作系统上工作,他们不想考虑UTF-8以外的任何东西。

如果您认为binmode()是丑陋且不必要的(并且不包含命令行参数),您可能会考虑与{{1}具有类似效果的utf8::all包}}。

或者您使用* nix,我建议在封闭脚本中perl -CSDL让Perl在UTF-8环境中实现它。