in reply to Negative array subscript method call bug?

As a general rule, perl error messages try to be as short as possible while still conveying all of the neccessary info that sets *this* type of error apart from *that* type of error.

The main motivation for this (as i understand it) is to keep them short for people who allready understand the various classes of problems, and just need a quick pointer to the line number and the type of think they screwed up.

If/when people are confused by perl error messages, they should ALWAYS consult perldiag, or use diagnostics

laptop:~> perl -Mdiagnostics -e 'my @x; $x[-1]->meth' Modification of non-creatable array value attempted, subscript -1 at - +e line 1 (#1) (F) You tried to make an array value spring into existence, and th +e subscript was probably negative, even counting from end of the arr +ay backwards. Uncaught exception from user code: Modification of non-creatable array value attempted, subscript + -1 at -e line 1.

Replies are listed 'Best First'.
Re^2: Negative array subscript method call bug?
by BUU (Prior) on Aug 07, 2004 at 19:20 UTC
    Yes, buy why does doing ->meth involve a modification or a creation of the left hand side?

      I started to write this...

      It doesn't. perl can't even make it that far because it can't figure out what it is you are trying to call "meth" on. Before it ever even gets arround to trying, it has to "make an array value spring into existence" and when it tried, it found that "subscript -1" ment "the subscript was (probably) negative" so ultimately you were asking it to set (aka: modify) a "non-creatable array value"

      ...but then i started to see your point: "Modification" ? why is refrencing the (non-creatable) array value to call a method on it considered a modification?

      It would make more sense to say something like "Reference of non-creatable array value attempted"...

      laptop:~> perl -e '$y = \$x[-1000];' Modification of non-creatable array value attempted, subscript -1000 a +t -e line 1.
        Hint: in a method call, the object is passed as the first parameter. Perl allows subroutines to modify parameters.
        How about just "method called on undefined value"?

        perl -e'$x= $x[-1]' $x is, of course, undefined.

        So logically $x=$x[-1];$x->meth and $x[-1]->meth should produce the same error, right? Theres no attempt at creation anywhere. Just trying to find an index that doesn't exist.

         $x[1]->meth produces the "Can't call method on undefined value" error, so why is -1 different than 1 when neither exist?