A word-counting program that uses the redo statement. : Redo « Statement « Perl






A word-counting program that uses the redo statement.


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

 








Related examples in the same category

1.Using the redo statement in a while structure.
2.redo statement
3.While loop, foreach loop, and block and redo
4.Using a label without a loop and the redo statement