http://www.perlmonks.org?node_id=521359


in reply to Obtaining terms in an expansion

It's not clear to me what you want. Maybe it's something like

my $C; if (@$ar) { $C = 1; foreach my $row (@$arr) { my $sum = 0; foreach my $ele (@$row) { $sum += $ele; } $C *= $sum; } }

By the way, you shoulnd'y use $a and $b as variable names to avoid conflicts with some special variables.

Update: Or maybe

my $cols = @{$arr->[0]}; my $C; foreach my $col_idx (0 .. $cols-1) { $C->[$col_idx] = 1; foreach my $row (@$arr) { $C->[$col_idx] *= $row->[$col_idx]; } }