I suspect you can assign 1 to it, but other values are silently ignored. I tried your code with $[=1, and lo and behold:$[ The index of the first element in an array, and of the first character + in a substring. Default is 0, but you could theoretically set it to 1 to ma +ke Perl behave more like awk (or Fortran) when subscripting and when evaluatin +g the index() and substr() functions. (Mnemonic: [ begins subscripts.) As of release 5 of Perl, assignment to $[ is treated as a compiler dir +ective, and cannot influence the behavior of any other file. (That's why you can o +nly assign compile-time constants to it.) Its use is deprecated, and by default w +ill trigger a warning. Note that, unlike other compile-time directives (such as strict), assi +gnment to $[ can be seen from outer lexical scopes in the same file. However, yo +u can use local() on it to strictly bind its value to a lexical block.
(shrug)perl -le '@arr=qw(10 1 2 3 4);$[=1;print $arr[$_],"\t",$_ for 0 .. $#a +rr;' 10 0 10 1 1 2 2 3 3 4 4 5
SSF
In reply to Re^2: how internally $#array is working in Perl
by sflitman
in thread how internally $#array is working in Perl
by kiruthika.bkite
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |