in reply to How can I add all the numbers in an array with out doing a foreach loop?
Can also use map() in a side-effects fashion.
my @nums = (1,2,3,4,5); my $sum = 0; map { $sum += $_ } @nums; print "\$sum = $sum\n";
The above code prints:
$sum = 15
Originally posted as a Categorized Answer.
|
|---|