This venerable variable demands more respect than many monks give it. Its might and glory are rarely actualized and this is a detriment to the perl community.

Observe this variables willingness to be noticed.
$[++; # No go. $[+=1; # Not happening $[ = $[; # Works. $[ = $[ + 1; # That will work! print \$[; # Ok, works. $[ = \$[; # which also works print $[; # Whoo fun!
Take notice to 'print \$[;' not to be confused with '$[ = \$[; print $[;', but the fun doesn't stop here monks!
$[=-1; @_=qw/foo bar baz/; print $_[-1]; # foo print $_[-2]; # bar print $_[-3]; # foo
After playing with $[; I have taken note to this dire mistake that I apparently have made habit. And, now I have decided to publish a finding to enlighten all. This idiom is wrong, and must be corrected at all cost.
#WRONG: for(my $i=0; $i<$#foo; $i++){} #RIGHT: for(my $i=$[; $i<$#foo; $i++){}

However, for the same reason this idiom is also wrong:
#WRONG: foreach(0..$#foo){} #RIGHT: foreach($[..$#foo){}
Now that two bad commonplace practices have been exposed, I suggest that we enable warnings to be issued for people who use the 0..$#foo. These willy-nilly coding practices are detrimental should be discouraged. I see them much more severe than addressing an element with the array sigil, at least Perl can correct for that.

Evan Carroll
www.EvanCarroll.com

In reply to $[ is under respected. by EvanCarroll

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.