From: Rafael Garcia-Suarez Date: Tue, 7 Apr 2009 10:31:16 +0000 (+0200) Subject: Deprecate assignment to $[ X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=55b6781562aff32ef6499c4f263ab251254ca5cb;p=p5sagit%2Fp5-mst-13.2.git Deprecate assignment to $[ Based on a patch by James Mastros : Subject: Deprecating $[ Message-ID: --- diff --git a/op.c b/op.c index b889319..517f648 100644 --- a/op.c +++ b/op.c @@ -4355,6 +4355,7 @@ Perl_newASSIGNOP(pTHX_ I32 flags, OP *left, I32 optype, OP *right) PL_eval_start = 0; else { if (!PL_madskills) { /* assignment to $[ is ignored when making a mad dump */ + deprecate("assignment to $["); op_free(o); o = newSVOP(OP_CONST, 0, newSViv(CopARYBASE_get(&PL_compiling))); o->op_private |= OPpCONST_ARYBASE; diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 70a432d..d958262 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -4661,6 +4661,11 @@ you can write it as C to avoid this warning. (F) The "use" keyword is recognized and executed at compile time, and returns no useful value. See L. +=item Use of assignment to $[ is deprecated + +(D deprecated) The C<$[> variable (index of the first element in an array) +is deprecated. See L. + =item Use of bare << to mean <<"" is deprecated (D deprecated, W syntax) You are now encouraged to use the explicitly quoted diff --git a/pod/perlvar.pod b/pod/perlvar.pod index 914eebe..7c61a05 100644 --- a/pod/perlvar.pod +++ b/pod/perlvar.pod @@ -1037,8 +1037,9 @@ subscripting and when evaluating the index() and substr() functions. As of release 5 of Perl, assignment to C<$[> is treated as a compiler directive, and cannot influence the behavior of any other file. -(That's why you can only assign compile-time constants to it.) -Its use is highly discouraged. +(That's why you can only assign compile-time constants to it.) Its +use is deprecated, and will trigger a warning (if the deprecation +L category is enabled. You did C, right?) Note that, unlike other compile-time directives (such as L), assignment to C<$[> can be seen from outer lexical scopes in the same file. diff --git a/t/lib/warnings/op b/t/lib/warnings/op index cc968c7..64217c7 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -1094,3 +1094,12 @@ Deprecated use of my() in false conditional at - line 6. Deprecated use of my() in false conditional at - line 7. Deprecated use of my() in false conditional at - line 8. Deprecated use of my() in false conditional at - line 9. +######## +# op.c +$[ = 1; +use warnings 'deprecated'; +$[ = 2; +no warnings 'deprecated'; +$[ = 3; +EXPECT +Use of assignment to $[ is deprecated at - line 4. diff --git a/t/op/each_array.t b/t/op/each_array.t index b0665e1..2389473 100644 --- a/t/op/each_array.t +++ b/t/op/each_array.t @@ -1,4 +1,4 @@ -#!./perl -w +#!./perl BEGIN { chdir 't' if -d 't'; @@ -6,6 +6,8 @@ BEGIN { require './test.pl'; } use strict; +use warnings; +no warnings 'deprecated'; use vars qw(@array @r $k $v); plan tests => 48; diff --git a/t/op/substr.t b/t/op/substr.t index 81c87be..c3fa6e1 100755 --- a/t/op/substr.t +++ b/t/op/substr.t @@ -1,4 +1,4 @@ -#!./perl -w +#!./perl #P = start of string Q = start of substr R = end of substr S = end of string @@ -7,6 +7,7 @@ BEGIN { @INC = '../lib'; } use warnings ; +no warnings 'deprecated'; $a = 'abcdefxyz'; $SIG{__WARN__} = sub {