programming-examples/perl/Statement/A word-counting program that uses the redo statement.pl
2019-11-15 12:59:38 +01:00

13 lines
339 B
Perl

#!/usr/local/bin/perl
$total = 0;
for ($count = 1; $count <= 3; $count++) {
$line = <STDIN>;
last if ($line eq "");
$line =~ s/^[\t ]*//;
$line =~ s/[\t ]*\n$//;
redo if ($line eq "");
@words = split(/[\t ]+/, $line);
$total += @words;
}
print ("The total number of words is $total\n");