You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
501 B
Perl

#!/usr/local/bin/perl
$total = &get_total;
if ($total eq "error") {
print ("No input supplied.\n");
} else {
print("The total is $total.\n");
}
sub get_total {
$value = 0;
$inputline = <STDIN>;
$inputline =~ s/^\s+|\s*\n$//g;
if ($inputline eq "") {
return ("error");
}
@subwords = split(/\s+/, $inputline);
$index = 0;
while ($subwords[$index] ne "") {
$value += $subwords[$index++];
}
$retval = $value;
}