programming-examples/perl/Array/Sum values in an array.pl

8 lines
136 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
@array = (1, 2, 3);
$running_sum = 0;
foreach $element (@array) {
$running_sum += $element;
}
print "Total = $running_sum";