A very Happy New Year to all.
Here's a question to kick off the new year: I've two arrays containing an equal number of digits. I want to multiply the digits from array1 with the corresponding digits from array2. With warnings enabled, I get the "Use of uninitialized value in multiplication (*)" warning. I try to fix that in the following code.
That suppresses the warning but should I be worry about it in the first place? Is there a better way to do the above?my $sum = 0; for (0..@weights) { $weights[$_] = $weights[$_] || 0; $digits[$_] = $digits[$_] || 0; $sum += $weights[$_] * $digits[$_]; }
Thank you so much in advance :)
In reply to A better way than || by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |