I'm stunned. I'd always assumed that $[ mods were applied to the index
before anything else happens. My feeling on this matter, which must be
missing from the test suite, is that an appropriate path would be to
determine how it should be, add tests to test that it is that way,
make it that way, and make some noise about it in the release notes.
$ perl -wle'$[=-1; print substr("abcdefghij", -2);'
should give j not ij.
doesn't mention $[
and says negs start from the tail;
doesn't mention negatives at
all while it discourages the use of $[.
so the behavior you list seems to all be working as documented.
Left undefined (and unexplored in your post) are the situations where
the index is greater than or equal to zero and less than a positive $[
greater than one.
wow, with a $[ of 2, a substr starting from 1 died with
panic: sv_setpvn called with negative strlen at -e line 1.
the -f substr docs say clearly
# substr EXPR,OFFSET,LENGTH
# substr EXPR,OFFSET
Extracts a substring out of EXPR and returns it. First character is at
offset 0 , or whatever you've set $[ to (but don't do that). If OFFSET
is negative (or more precisely, less than $[ ), starts that far from
the end of the string.
so maybe the implementation should be changed to match the documentation.