Try this one for size:

perl -e '$x[-1] = 0;' __OUTPUT__ Modification of non-creatable array value attempted, subscript -1 at - +e line 1.

It would appear that you cannot autovivify an array element by counting backward from the last element using negative subscripts. Likewise, this will throw the same error:

perl -e '@x = ( 1, 2, 3 ); $x[-4] = 0;'

Again, this is attempting to autovivify an element prior to the first element ($x[0]) by using a negative index that will count backward past the beginning of the array.

I don't consider the fact that you can't do this to be a bug, if ever there were a feature, this is it. ;)

Update: After reading your update, I just wanted to comment: I really think that the problem is two-fold: First, you're attempting to autovivify by indexing backwards from an array that has no elements (so there is no concept of the last element). The second problem is that even if the array has elements (thus creating a concept of 'last element'), attempting to index to the left of the first element (ie, before $x[0]) is another impossibility; you can't autovivify an element prior to the first element of an array. In an array that contains no elements, you're breaking both rules; you're attempting to count backward from the last element, when there is no last element. And since there is no last element, any element you autovivify by counting backwards will have to come before the nonexistant first element. It's madness.


Dave


In reply to Re: Negative array subscript method call bug? by davido
in thread Negative array subscript method call bug? by BUU

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.