in reply to How can I add all the numbers in an array with out doing a foreach loop?
He's a rather ridiculous solution which avoids using the addition operator. It only works for positive integers.
my @quans = (2, 5, 8, 12, 15, 88); my $total = scalar(map {1 .. $_} @quans); print "$total.\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Answer: How can I add all the numbers in an array with out doing a foreach loop?
by choroba (Cardinal) on Mar 09, 2017 at 17:00 UTC |