Learning Perl by Randal L. Schwartz; brian d foy; Tom Phoenix

Learning Perl by Randal L. Schwartz; brian d foy; Tom Phoenix

Author:Randal L. Schwartz; brian d foy; Tom Phoenix
Language: eng
Format: mobi
Tags: COMPUTERS / Programming Languages / Perl
ISBN: 9781449304584
Publisher: O'Reilly Media
Published: 2011-06-16T18:30:00+00:00


foreach (@words) {

## redo comes here ##

print "Type the word '$_': ";

chomp(my $try = <STDIN>);

if ($try ne $_) {

print "Sorry - That's not right.\n\n";

$errors++;

redo; # jump back up to the top of the loop

}

}

print "You've completed the test, with $errors errors.\n";

Like the other two operators, redo will work with any of the five kinds of loop blocks, and it will work with the innermost loop block when they’re nested.

The big difference between next and redo is that next will advance to the next iteration, but redo will redo the current iteration. Here’s an example program that you can play with to get a feel for how these three operators work:

foreach (1..10) {

print "Iteration number $_.\n\n";

print "Please choose: last, next, redo, or none of the above? ";

chomp(my $choice = <STDIN>);

print "\n";

last if $choice =~ /last/i;

next if $choice =~ /next/i;

redo if $choice =~ /redo/i;

print "That wasn't any of the choices... onward!\n\n";

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.