programming-examples/perl/Statement/Exits using the last statement.pl
2019-11-15 12:59:38 +01:00

18 lines
405 B
Perl

#!/usr/local/bin/perl
$total = 0;
while (1) {
$line = <STDIN>;
if ($line eq "") {
last;
}
chop ($line);
@numbers = split (/[\t ]+/, $line);
foreach $number (@numbers) {
if ($number =~ /[^0-9]/) {
print STDERR ("$number is not a number\n");
}
$total += $number;
}
}
print ("The total is $total.\n");