Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Disable Control +C

by PilotinControl (Monk)
on Mar 12, 2013 at 20:29 UTC ( #1023045=note: print w/ replies, xml ) Need Help??


in reply to Re: Disable Control +C
in thread Disable Control +C

Here is my code:

#!/usr/bin/perl use 5.010; use warnings; use strict; printf (" #############################\n"); printf (" ########## TEST MENU ########\n"); printf (" #############################\n"); sleep(2); $SIG{INT} = 'IGNORE'; while(1) { printf ("WHAT DO YOU WANT TO DO\n"); printf (" * * * * *\n"); printf (" 1- Option\n"); printf (" 2- Option\n"); printf (" 5-Exit \n"); printf (" * * * * *\n"); my $choose = <STDIN>; chomp($choose); if($choose eq 1) { option->client; } elsif($choose eq 2) { option2(); } elsif($choose eq 5) { printf("Good Bye :-)\n"); sleep(2); exit(1); }; };

When you hit control +c within the program it sends errors to the screen...it prohibits control +c to kill the program. I have to choose option 5 to exit which is what I want...now to avoid the errors? Thanks.


Comment on Re^2: Disable Control +C
Download Code
Replies are listed 'Best First'.
Re^3: Disable Control +C
by Athanasius (Abbot) on Mar 13, 2013 at 02:30 UTC

    Hello PilotinControl,

    You just need to loop on $choose until it is defined:

    ... my $choose = <STDIN>; $choose = <STDIN> until defined $choose; # <-- Add this line chomp $choose; ...

    That will remove the warnings you are currently seeing.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Thanks that worked!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2015-07-28 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls