Perl | catching the letter 'Q' for exit.

Hi all,

I made a simple script with a prompt menu in Perl. All working good, but I want to add an option while the program is running that on every time when the user press 'Q' the program will exit.

I know I can use $SIG{'INT'} or any other %SIG option. This option is a unix signal which I don't want to use.

Is there any way to do it?
In the menu there is an option to press Q for exit but I want to enable it even when the script is running .

Thanks dudes,:rolleyes:

you can't easily without messing with the terminal

whats wrong with ctrl-C?

use Term::ReadKey;
ReadMode 4;

until ( ReadKey(-1) eq 'Q' ) {
   ... Your Program Here ...
}

ReadMode 0; # Reset tty before exiting
exit;

There you are, sir.

1 Like

well I never did.

excellent.