rschupp / PAR-Packer

(perl) Generate stand-alone executables, perl scripts and PAR files https://metacpan.org/pod/PAR::Packer
Other
48 stars 13 forks source link

how to pass perl option `-C` #89

Closed VladimirAlexiev closed 3 months ago

VladimirAlexiev commented 5 months ago

Currently I run the tool I'm trying to package in https://github.com/rschupp/PAR-Packer/issues/88 like this:

perl -S -C rdfpuml.pl $1

I need the -C option otherwise Unicode appearing in input files get mangled.

How to pass this option to pp. If I try to put it on the first script line

#!perl -w -C

I get error

Too late for "-C" option at d:\GitHub\rdf2rml\bin/rdfpuml.pl line 1.
rschupp commented 5 months ago

Try using the open pragma (see https://perldoc.perl.org/open) with the appropriate runes at the top of rdfpuml.pl, probably

use open ":std", ":utf8";
jonassmedegaard commented 3 months ago

A better place to look seems to be man perlunicook, specifically prescription 18:

  ℞ 18: Make all I/O and args default to utf8
         $ perl -CSDA ...
     or
         $ export PERL_UNICODE=SDA
     or
         use open qw(:std :encoding(UTF-8));
         use Encode qw(decode);
         @ARGV = map { decode('UTF-8', $_, 1) } @ARGV;

Besides changing how you call the script, you also previously used :encoding(:encoding(UTF-8) which does strict UTF-8 parsing. You current change to using :utf8 does relaxed parsing.

Please also note that command-line option -CSDL does not always use UTF-8, but switches encoding based on environment variables (see prescription 16. I recommend to stay with unconditionally using UTF-8 unless you have special needs.

rschupp commented 3 months ago

@jonassmedegaard Thanks for the explanation. Closing the issue as there's nothing actionable here.