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 likeawk (or Fortran) when subscripting and when evaluating the index() and substr() functions.
As of release 5 of Perl, assignment to$[
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$[
could be seen from outer lexical scopes in the same file, unlike other compile-time directives (such asstrict). 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 thearybase module.
As of Perl v5.30.0, or underuse v5.16
, orno feature "array_base"
,$[
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.
Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.
The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.