It's a case of which error came first.
In this first case, $x[ 0 ] exists, so $x[ -1 ] can be translated as
$x[ @x - 1 ] ==> $x[ 1 - 1 ] ==> $x[ 0 ]
which is valid and currently undef, so the error occurs when try to indirect through undef for the method call.
P:\test>perl -e" @x = undef; $x[ -1 ]->fred()" Can't call method "fred" on an undefined value at -e line 1.
But in this case you have $x[ 0 - 1 ], which translates to a post-normalisetion, negative index (-1), which is illegal.
So that's the error you see, and the indirection is never attempted.
P:\test>perl -e" $x[ -1 ]->fred()" Modification of non-creatable array value attempted, subscript -1 at - +e line 1.
Of course, the subscript normalisation also incorporates $[, but the always 0...right :)
In reply to Re^5: Negative array subscript method call bug?
by BrowserUk
in thread Negative array subscript method call bug?
by BUU
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |