in reply to 'my' headache...why doesn't this work?

Hi

Consider it written this way around instead

foreach (@data) { my $columnsum += $_->[$colnum]; } print $columnsum; # is undef, and would give a strict error

Your $columnsum is being repeatedly re-localised at each step of the foreach loop, and doesn't get a value outside of it.

Interestingly, use strict doesn't seem to help here. I'd either expect strict to complain about a subsequent use of $columnsum outside of the (implicit) scope of the post-positional for loop, or for warnings to complain about masking a previously declared lexical variable. Can any wise folk here explain why it works like this?

//=\\