The last statement is the value to return
#!/usr/bin/perl -w
use strict;
my $total = total(1, 7, 5, 4, 9);
print "the total is: $total\n";
my $sum_of_100 = total(1..100);
print "the sum of 100 is: $sum_of_100\n";
sub total {
my $total = 0;
$total += $_ for @_;
$total;
}
Related examples in the same category