A word-counting program that uses the next statement. : Next « Statement « Perl






A word-counting program that uses the next statement.

 

#!/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"); 

   
  








Related examples in the same category

1.Using the next statement in a foreach structure.
2.Next statement
3.Next if
4.Going onto the Next
5.Using both next and continue
6.next with condition
7.Next statement with if statement