Sum and product of an array: Difference between revisions

Content added Content deleted
(→‎{{header|Perl}}: 'product' subroutine isn't in List::Util.)
(→‎{{header|Perl}}: Add alternate perl version with List::Util.)
Line 341: Line 341:
my @list = (1, 2, 3);
my @list = (1, 2, 3);
my $s = sum @list;
my $s = sum @list;

Alternate

'''Libraries:''' List::Util
use List::Util qw(reduce);
my @list = (1, 2, 3);
my $sum = reduce { $a + $b } @list;
my $product = reduce { $a * $b } @list;


Alternate
Alternate