in reply to undefined elements in array

I think you're getting warnings because you're comparing an undefined value. Just try testing for defined:
$array[$i][$j] = 0 unless defined $array[$i][$j];