develooper Front page | perl.perl5.porters | Postings from December 2015

[perl #127063] Setting $[ = 0 should not generate a warning

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
December 29, 2015 00:10
Subject:
[perl #127063] Setting $[ = 0 should not generate a warning
Message ID:
rt-4.0.18-7082-1451347820-1266.127063-15-0@perl.org
On Mon Dec 28 14:19:28 2015, jim.avera@gmail.com wrote:
> 
> This is a bug report for perl from jim.avera@gmail.com,
> generated with the help of perlbug 1.40 running under perl 5.20.2.
> 
> -----------------------------------------------------------------
> perl -we 'local $[ = 0;'
> Use of assignment to $[ is deprecated at -e line 1.
> 
> This warning makes some old code noisy even if the only thing the code
> does
>  is to set $[ to zero to to protect against callers leaving $[ in
> another
> state (which was possible Perl 4, at least).
> 
> An example is the html2ps utility distributed with Ubuntu (in this
> particular
> case it is wholly unnecessary but nevertheless the $[=0 seems to have
> been
> inherited from some Getopt examples from way back).
> 
> Regardless, it would be nice if the warning was only issued when $[ is
> set to
> something other than zero.
> 

To facilitate discussion of this ticket, here's the current documentation in blead pod/perlvar.pod for $[:

##########
This variable stores the index of the first element in an array, and
of the first character in a substring.  The default is 0, but you could
theoretically set it to 1 to make Perl behave more like B<awk> (or Fortran)
when 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.

Prior to Perl v5.10.0, assignment to C<$[> could be seen from outer lexical
scopes in the same file, unlike other compile-time directives (such as
L<strict>).  Using local() on it would bind its value strictly to a lexical
block.  Now it is always lexically scoped.

As of Perl v5.16.0, it is implemented by the L<arybase> module.  See
L<arybase> for more details on its behaviour.

Under C<use v5.16>, or C<no feature "array_base">, C<$[> no longer has any
effect, and always contains 0.  Assigning 0 to it is permitted, but any
other value will produce an error.

Mnemonic: [ begins subscripts.

Deprecated in Perl v5.12.0.
#####

Thank you very much.


-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=127063

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About