The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

emen (1) [Avatar] Offline
#1
I'm a bit confused why this script needs a "continue" part, does the below code achieve the same effect? Any input are appreciated. Thanks! - Emen

#!/usr/bin/perl -wl

while (1) {
printf "Are you sure? [y/n] ";
$answer=<STDIN>;
defined $answer or exit;
chomp $answer;
($answer ne 'y' and $answer ne 'n') or last;
}
tmaher (37) [Avatar] Offline
#2
Re: Confusion about script "confirmation" on p354
> I'm a bit confused why this script needs a "continue"
> part, does the below code achieve the same effect?
> Any input are appreciated. Thanks! - Emen

Your version lacks the "Please respond with …" message,
which needs to be issued if the input is empty ("") or
the condition ($answer ne 'y' &hellip) is True. That's understandable,
because it's difficult to provide that
service without the continue block shown on p. 354, which makes
it easy, and with high readability too. In some simpler cases you could indeed
do your own coding to achieve this effect, but IMHO the approach based on
continue is a much better practice.

> #!/usr/bin/perl -wl
>
> while (1) {
> printf "Are you sure? [y/n] ";
> $answer=<STDIN>;
> defined $answer or exit;
> chomp $answer;
> ($answer ne 'y' and $answer ne 'n') or last;