From: Father Chrysostomos Date: Sun, 26 Jul 2009 09:27:42 +0000 (+0100) Subject: Allow -C on the #! line when it is identical to -C on the command line. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4ba71d51f72efb2af8dc9748dd62219261f2e1fd;p=p5sagit%2Fp5-mst-13.2.git Allow -C on the #! line when it is identical to -C on the command line. Change from dieing whenever -C is seen on the #! line, to dieing only when it differs from that on the command line, or was not specified on the command line. --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 1775163..2623010 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -4196,8 +4196,15 @@ system call to call, silly dilly. =item Too late for "-%s" option (X) The #! line (or local equivalent) in a Perl script contains the -B<-M>, B<-m> or B<-C> option. This is an error because those options -are not intended for use inside scripts. Use the C pragma instead. +B<-M>, B<-m> or B<-C> option. + +In the case of B<-M> and B<-m>, this is an error because those options are +not intended for use inside scripts. Use the C pragma instead. + +The B<-C> option only works if it is specified on the command line as well +(with the same sequence of letters or numbers following). Either specify +this option on the command line, or, if your system supports it, make your +script executable and run it directly instead of passing it to perl. =item Too late to run %s block diff --git a/pod/perlrun.pod b/pod/perlrun.pod index c3b30c8..994aecb 100644 --- a/pod/perlrun.pod +++ b/pod/perlrun.pod @@ -342,10 +342,10 @@ that enabled the use of Unicode-aware "wide system call" Win32 APIs. This feature was practically unused, however, and the command line switch was therefore "recycled".) -B Since perl 5.10.0, the -C option can no longer be used -on the #! line. It wasn't working there anyway, since the standard streams +B 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 use binmode() instead to get the desired behaviour. +You can also use binmode() to set the encoding of an I/O stream. =item B<-c> X<-c> diff --git a/t/run/switchC.t b/t/run/switchC.t index 41dba49..9e52ad3 100644 --- a/t/run/switchC.t +++ b/t/run/switchC.t @@ -13,7 +13,7 @@ BEGIN { BEGIN { require "./test.pl"; } -plan(tests => 6); +plan(tests => 7); my $r; @@ -59,3 +59,7 @@ $r = runperl( switches => [ '-CA', '-w' ], args => [ chr(256) ] ); like( $r, qr/^256(?:\r?\n)?$/s, '-CA: @ARGV' ); +$r = runperl( switches => [ '-CS', '-w' ], + prog => "#!perl -CS\nprint chr(256)", + stderr => 1, ); +like( $r, qr/^$b(?:\r?\n)?$/s, '#!perl -C' ); diff --git a/toke.c b/toke.c index 885027e..56e9620 100644 --- a/toke.c +++ b/toke.c @@ -3999,7 +3999,15 @@ Perl_yylex(pTHX) const char *d1 = d; do { - if (*d1 == 'M' || *d1 == 'm' || *d1 == 'C') { + bool baduni = FALSE; + if (*d1 == 'C') { + const char *d2 = d1; + d2++; + parse_unicode_opts( (const char **)&d2 ) + == PL_unicode + || (baduni = TRUE); + } + if (baduni || *d1 == 'M' || *d1 == 'm') { const char * const m = d1; while (*d1 && !isSPACE(*d1)) d1++;