in reply to $#{$array_ref} changes in loop

You have two loops dependent on the dimensions of the same array and only one control variable that is set up to exceed its proper bounds, where two iteration variables would work ok - the autovivication effect can better be thought of as a symptom of incorrect loop construction - i.e. don't try to address that problem on its own, but address the more abstract one of loop construction to solve this elegantly and maintainably.

There are a number of rules for constructing loops safely in any language that all apply here. Another rule is:

Don't modify any of the control variables from within a loop, whether it be the iterator or the start and stop limits or the compiler or interpreter is apt to stumble and behave unpredictably".

It takes experience to know more such rules but they relate to loop construction technique more than anything else. Three of the lines of code look functionally to be exactly the three parts of a 3-arg for loop, so better just write that, e.g.:

for my $i ( 0 .. $#$eventscores ) { # forces readonly for ( my $j = $i; $eventscores->[$j][0] == $eventscores->[$i][0]; $j++ ){ push (@scores, $eventscores->[$j][2] ); } # more code unrelated to loop }
Update: or if you didn't really want to exit the innerloop on a non match (I find that functionally a bit weird though you might possibly be right about it) ...
for my $i ( 0 .. $#$eventscores ) { # forces readonly for ( my $j = $i; $j <= $#$eventscores; $j++ ){ if ( $eventscores->[$j][0] == $eventscores->[$i][0] ) { push (@scores, $eventscores->[$j][2] ); } } # more code unrelated to loop }
__________________________________________________________________________________

^M Free your mind!