Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Redirecting"enter" when an external command is running..

by perl_mystery (Beadle)
on Dec 04, 2010 at 22:33 UTC ( [id://875423]=note: print w/replies, xml ) Need Help??


in reply to Re: Redirecting"enter" when an external command is running..
in thread Redirecting"enter" when an external command is running..

That's not what I want.If i change == to eq,the variable $choice still picks up the "enter",while the script is running ,any "enter" buttons should be redirected so that the $choice variable doesn't pick it.

  • Comment on Re^2: Redirecting"enter" when an external command is running..

Replies are listed 'Best First'.
Re^3: Redirecting"enter" when an external command is running..
by ww (Archbishop) on Dec 05, 2010 at 01:24 UTC
    Change line 1 from print "Running Script....\n";

    to print "Running Script: <big><b>Do NOT hit enter!</b></big>\n"; perhaps ?

          :-)

      I changed the order of the program execution to resolve this problem but i have one more question now...I am doing a check on $choice for value 1 or 2 ,if not print "INVALID CHOICE" and then exit the program.Is there a way to ask the user to re-enter the choice rather than exiting the program?

      print "\nEnter your choice: "; my $choice = <>; chomp ($choice); if($choice != (1||2)){ print "/*******************************************************/\n +"; print "INVALID CHOICE\n"; print "/*******************************************************/\n +"; exit; }

        OR (or || ) with a negative can be very confusing... and in your sample, would not do what you want. You want the user who enters anything other than "1" or "2" to be reprompted... so you want

        if ( $choice != 1 && $choice != 2 ) {

        As for a way to do it (just one of many, and one about which some purists will howl) is with a label and a goto:

        #!/usr/bin/perl use strict; use warnings; # 875438 START: print "\nEnter your choice: "; my $choice = <>; chomp ($choice); if ( $choice != 1 && $choice != 2 ) { print "INVALID CHOICE\n"; goto START; } else { print "\$choice: $choice \n"; }

        When executed, you'll see:

        >pl_test/875438.pl Enter your choice: 4 INVALID CHOICE Enter your choice: 3 INVALID CHOICE Enter your choice: 2 $choice: 2 >

        A better option might be to re-reorganize your program; test the $choice and if you have a 1 or a 2, do whatever it is that you want; then elsif and reprompt there.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-16 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found