From perlvar:
$[ 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.
I suspect you can assign 1 to it, but other values are silently ignored. I tried your code with $[=1, and lo and behold:
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
(shrug)

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.