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;