Functional List Processing
Reduce Sum
Accumulate list values into one total.
Reduce Sum
reduce_sum.pl
use strict;
use warnings;
my $bonus = ;
my @points = (2, 4, 6);
my $total = $bonus;
for my $point (@points) {
$total = $total + $point;
}
print "bonus=$bonus\n";
print "total=$total\n";
use strict;
use warnings;
my $bonus = ;
my @points = (2, 4, 6);
my $total = $bonus;
for my $point (@points) {
$total = $total + $point;
}
print "bonus=$bonus\n";
print "total=$total\n";
reduce-sum
A reduce-style pass combines many values into one value. This example uses a small accumulator so each step stays visible.