programming-examples/perl/Subroutine/The last statement is the value to return.pl

16 lines
260 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/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;
}