Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: comparison of character

by rjt (Deacon)
on Jul 16, 2013 at 11:39 UTC ( #1044563=note: print w/ replies, xml ) Need Help??


in reply to comparison of character

A couple other points to ponder:

print "Do you wish to update (Y/N)?\n";

You likely added the \n to ensure the prompt prints for the user. See $| to print without buffering, so you don't need the trailing newline:

$| = 1; print "Do you wish to update (Y/N)? ";

The overall structure leaves a bit to be desired. What about something more along these lines?

$| = 1; my $choice; do { print "Do you wish to update (Y/N)? "; $choice = lc <>; chomp $choice; } until ($choice =~ /^[yn]$/i); say "You picked `$choice'";

This will repeat the prompt if the input is invalid, and normalizes the input by converting it to lowercase, to simplify your code later in the program.


Comment on Re: comparison of character
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1044563]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-08-23 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (176 votes), past polls