5

Trying to run this little perl program from parsCit:

parsCit-client.pl e1.txt Too late for -CSD option at [filename] line 1

e1.txt is here: http://dl.dropbox.com/u/10557283/parserProj/e1.txt

I'm running the program from win7 cmd, not Cygwin.

filename is parsCit-client.pl - entire program is here:

#!/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";
patrick
  • 16,091
  • 29
  • 100
  • 164
  • 4
    **Stop!** Do not ever use the `use encoding` pragma! It is terribly broken. Use the `use open` pragma instead. But you already have your bases covered with `-CSD`. You could lose the `-CSD` if you said `use open qw(:utf8 :std); use warnings qw(FATAL utf8);`. – tchrist Mar 20 '12 at 02:49

2 Answers2

8

From perldoc perlrun, about the -C switch:

Note: Since perl 5.10.1, if the -C option is used on the "#!" line, it must be specified on the command line as well, since the standard streams are already set up at this point in the execution of the perl interpreter. You can also use binmode() to set the encoding of an I/O stream.

Which is presumably what the compiler means by it being "too late".

In other words:

perl -CSD parsCit-client.pl 
TLP
  • 66,756
  • 10
  • 92
  • 149
  • You wouldn’t have to do that on Unix. But you had best add `-S` to search the path for the file. See my up-top comment for IMHO a better approach. – tchrist Mar 20 '12 at 02:48
  • 1
    @tchrist I am not familiar with these switches, so I have no idea what you mean. I assume his file is in the current directory. ETA: You should add your comment as an answer, if you feel it is the correct answer. – TLP Mar 20 '12 at 02:52
2

Because command-line options in a #! "shebang" are not passed consistently across all operating systems (see this answer), and Perl has already opened streams before parsing the script shebang, and so cannot compensate for this in some older OSs, it was decided in bug 34087 to forbid -C in the shebang. Of course, not everyone was happy with this "fix", particularly if it would have otherwise worked on their OS and they don't want to think about anything other than UTF-8.

If you think binmode() is ugly and unnecessary (and doesn't cover command-line arguments), you might like to consider the utf8::all package which has a similar effect to perl -CSDL.

Or were you using *nix, I would suggest export PERL_UNICODE="SDA" in the enclosing script to get Perl to realise it's in a UTF-8 environment.

Community
  • 1
  • 1
Cedric Knight
  • 249
  • 2
  • 4