in reply to Negative array subscript method call bug?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Negative array subscript method call bug?
by BUU (Prior) on Aug 07, 2004 at 10:00 UTC |