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];
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|