I’m building a count matrix in Perl using AoA: my @aoa = () then call $aoa[$i][$j]++ whenever I need to increment a specific cell. Since some cells are not incremented at all, they are left undef (these are equivalent to 0 counts).
I would like to print some lines from the matrix, but I get errors for undef cells (which I would simply like to print as zeros). what should I do?
Classically:
Modern Perl (5.10 or later):
That is a lot more succinct and Perlish, it has to be said.
Alternatively, run through the matrix before printing, replacing
undefwith 0.