in reply to do-while loop question

I never loop on simple yes/no answer questions. It's unnecessarily complex and doesn't usually add much value to a program. In your example, I would only accept an answer starting with Y/y and die if any other input value was detected. For example:
print "Are you ready to proceed? [y/N]: "; chomp(my $answer = <STDIN>); die "Ciao!\n" if ($answer !~ /^y/i);
Now 8 lines of somewhat torturous logic have been reduced to 3 simple statements.

Replies are listed 'Best First'.
Re:x2 do-while loop question
by grinder (Bishop) on Mar 13, 2003 at 11:59 UTC

    Quite true. But then again, if you're only looking at the beginning of the string, chomping becomes superfluous, and you don't even need to spring a variable into existence:

    print "Are you ready to proceed? [y/N]: "; <STDIN> !~ /^y/i and die "Ciao!\n";

    I changed the structure of the second line because it seems to read better to me, don't shoot me, it's a question of style. So now we have one line down, two to go :)


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'

      I can throw it down to one line :)

      print "Are you ready to proceed? [y/N]: " and <> =~ /^y/i or die "ciao +\n";


      If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.