in reply to Re: How can I add all the numbers in an array with out doing a foreach loop?
in thread How can I add all the numbers in an array with out doing a foreach loop?
You can do it with grep as:
#!/user/bin/perl use strict; use warnings; my @array = (1,2,3,4,5,6,7,8,9,10); my $sum = 0; grep{$sum += $_} @array; print "\$sum = $sum\n"; exit(0);
The result is:
$sum = 55
|
|---|