programming-examples/perl/Statement/A word-counting program that uses the next statement.pl

11 lines
271 B
Perl
Raw Normal View History

2019-11-15 12:59:38 +01:00
#!/usr/local/bin/perl
$total = 0;
while ($line = <STDIN>) {
$line =~ s/^[\t ]*//;
$line =~ s/[\t ]*\n$//;
next if ($line eq "");
@words = split(/[\t ]+/, $line);
$total += @words;
}
print ("The total number of words is $total\n");