That doesn't explain why $#a is behaving so oddly when I retrieve its value.
When you set $#a, Perl needs an integer. If you give it something that's more than just an integer, it takes out the integer part and stores that in the appropriate place in the data structure it uses to represent the array. It throws out the rest of the information, as it doesn't need it.
When you read $#a, Perl looks in the underlying data structure and fetches the integer stored there. It returns it. It can't return any more information. It doesn't store it.
This is C-level stuff. If you're curious, see av.h, specifically the xpvav struct declaration and the xav_fill member. It holds an integer (see uconfig.h, I think), not an SV.
Update: I did misread the question. The right code to read is that of the av2arylen opcode in pp.c, which I really don't follow. Consider this program though, which shows that $#a isn't a plain integer, it's an SV with magic:
use Devel::Peek; my @a; Dump( $#a ); my $b = {foo=>1}; exit if $b + 0 > 0x10125000; $#a=$b; Dump( $#a );
In reply to Re^3: Putting weird things into $#array
by chromatic
in thread Putting weird things into $#array
by blokhead
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |