What good is -CSDA indicated only on the shebang line?

I'm looking for someone who will authoritatively confirm or correct what I think is aware of the -CSDA option in the shebang Perl script line.

See perldoc perlrun for documentation -CSDA . Briefly

  • S: STDIN , STDOUT and STDERR assumed in UTF-8
  • D: UTF-8 is the default PerlIO level for input and output streams
  • A: @ARGV elements are expected to be encoded in UTF-8.
  • In order for -CSDA have any effect, it must be specified on the command line, as in the perl -CSDA script.pl .

  • Until 5.10, -CSDA on the shebang line will fail, because standard streams would already be open, and @ARGV already full by the time it was encountered if -CSDA no longer on the command line.

  • After 5.10, -CSDA , which appears only on the shebang line, causes perl scream because of this problem.

  • A script with -CSDA , which was used to work with perl pre-5.10, had to remove -CSDA from the shebang line, because it was never called with these parameters on the command line (and the options, if they are specified exclusively on the shebang line, are nothing did not do).

I would like to get solid feedback which of my assumptions above are wrong.

+6
perl shebang unicode
source share
2 answers

Not sure how authority I am, but I know how it works.

  • Your first guess is almost certain. If the SDA parameters have any effect, they should be present when the interpreter starts. This may be due to -CSDA on the command line, or it may be due to the PERL_UNICODE environment variable or possibly some other way that I am not aware of.
  • Your second assumption is true, at least for 5.8.8. Note that the D flag still had a normal effect for threads opened with a script.
  • Your third assumption is correct. However, starting from 5.10.1, it will not scream if the corresponding flags are enabled through the PERL_UNICODE environment variable or some other mechanism.
  • Your fourth guess is usually incorrect. I assume that you are referring to a situation where the script is called directly, rather than referring to the perl interpreter using the script as an argument. There are two general cases.
    • On a system where the operating system determines that any file with the extension β€œ.pl” will be passed to the perl interpreter for execution, such as Windows, you may be right. But it can be argued that a script framework when invoked without -CSDA is the desired behavior, not a mysterious failure, because standard input and @ARGV are not UTF-8 as the script waits.
    • On a system that reads the shebang line when the script is executed directly, like most * nix shells, the command line parameters specified in the shebang line will be used when the interpreter is called, and therefore the -CSDA line on the shebang will be executed.
+3
source share

If your script

 #!/usr/bin/perl -CSDA 

and you start your script with

 ./script foo 

The OS will launch Perl as follows:

 /usr/bin/perl -CSDA ./script foo 

Changes in behavior come into play only when the script is run incorrectly, for example, using

 /usr/bin/perl ./script foo 

Fix do not remove -CSDA , the fix should properly call the script.

+3
source share

All Articles