in reply to Re^3: Negative array subscript method call bug?
in thread Negative array subscript method call bug?

Hint: in a method call, the object is passed as the first parameter. Perl allows subroutines to modify parameters.
  • Comment on Re^4: Negative array subscript method call bug?

Replies are listed 'Best First'.
Re^5: Negative array subscript method call bug?
by hossman (Prior) on Aug 08, 2004 at 08:09 UTC

    That doesn't strike me as a very legitimate reason, because method invocation isn't the only place where this happens. hence the other example I posted...

    laptop:~> perl -e '$y = \$x[-1000];' Modification of non-creatable array value attempted, subscript -1000 a +t -e line 1.

    ...there's nothing remotely close to a modification there.

      ...there's nothing remotely close to a modification there.

      Sure there is. The reference operator must have something to reference. And inorder to reference an element of an array the array element must exist. Thus before the reference can be taken it tries to create the element, but fails because it makes no sense. Try doing the same thing but with a positive index, and then print out how large the array is afterwards....


      ---
      demerphq

        First they ignore you, then they laugh at you, then they fight you, then you win.
        -- Gandhi


      Literally, you are correct, and the error message is misworded. However, this is an example of what I'm going to call for lack of a better term "modification context". Same applies to &foo($x[-1000]) or $x[-1000]->foo. That's what the error message is referring to.