Perl | catching the letter 'Q' for exit.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl | catching the letter 'Q' for exit.
# 1  
Old 05-11-2010
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,Smilie
# 2  
Old 05-11-2010
you can't easily without messing with the terminal

whats wrong with ctrl-C?
# 3  
Old 05-13-2010
Perl: Unbuffered Keyboard Read to Exit Running Code

Code:
use Term::ReadKey;
ReadMode 4;

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

ReadMode 0; # Reset tty before exiting
exit;

There you are, sir.
This User Gave Thanks to deindorfer For This Post:
# 4  
Old 05-17-2010
well I never did.

excellent.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Perl: trap signal 'exit': why I am not able to have it work??

First time trying to work with signals in Perl. Reviewing example I try it, but not able to get it work for 'exit'. I hope, I am correct, assuming, that the ending any code by exit $return_code; the $SIG{EXIT} should be de-referenced and processed?! So, I have such code, that, I assume,... (5 Replies)
Discussion started by: alex_5161
5 Replies

2. Shell Programming and Scripting

Replace specific letter in a file by other letter

Good afternoon all, I want to ask how to change some letter in my file with other letter in spesific line eg. data.txt 1 1 1 0 0 0 0 for example i want to change the 4th line with character 1. How could I do it by SED or AWK. I have tried to run this code but actually did not... (3 Replies)
Discussion started by: weslyarfan
3 Replies

3. Shell Programming and Scripting

Issue catching/reading 2 digits and 3 letter string between brackets

Hello I'm writing a handler for ffmpeg, and having troubles to catch some exceptions that may occour with certain files. In order to parse for video & subtitle maps, i've had to make the raw data easier to handle, until now this worked well, but basicly i've just been lucky... The input... (1 Reply)
Discussion started by: sea
1 Replies

4. Shell Programming and Scripting

[Solved] Perl, Deep recursion? exit() ignored?

Hi all, I am calling a subroutine which checks if a log file is writeable and if not, prints something stdout and also log something into the same file, which doesn't work neither of course. Anyway, there is enough exit() calls, that should stop it working, but the problem is, that I get the... (5 Replies)
Discussion started by: zaxxon
5 Replies

5. Shell Programming and Scripting

Perl Question Grep and exit status

Im being forced to write in perl. I prefer KSH or Expect, so I suppose its time to become more fluent with perl. I have the following problem. I want to loop through Filea and check that each line in Filea is resident in Fileb. Filea contents two four six eight houseboat Fileb... (4 Replies)
Discussion started by: sumguy
4 Replies

6. Shell Programming and Scripting

Letter Frequency Decryption Program in Perl

Hello, :/ (0 Replies)
Discussion started by: jvr42
0 Replies

7. Shell Programming and Scripting

exit ststus 9 from perl system command

HI all, can anyone tell me what does exit status 9 from perl's system function meant. I am using system fuction to execute a shell script as : my $s=system ('script.sh' ,arg1 ,arg2); print $s; the output is 9. Thanks in advance. !!:confused: (1 Reply)
Discussion started by: glamo_2312
1 Replies

8. Shell Programming and Scripting

Catching all Exit Codes

I have a Unix Script that has several exit in the middle. each returning seperate exit codes. I have to catch all the exit's and perform an operation say "Mail the status code" before the actual code completes. How can i do this in KSH ? (3 Replies)
Discussion started by: Sivaswami J
3 Replies

9. Shell Programming and Scripting

How to get exit status codes in bash from Perl?

I apologize if I have already posted this query. I scanned back quite a few pages but could not find such a query. If my perl code contains "exit(33)" how can I get that value in bash for use in a "if" statement. Thanks, Siegfried (5 Replies)
Discussion started by: siegfried
5 Replies

10. Shell Programming and Scripting

PERL: Trapping EXIT

Hey Everyone, Just starting with PERL (5.8.2) after years of KSH. Is there a way to trap the exit as you can in KSH (i.e., "trap EXIT_SCRIPT EXIT")? Thanks in advance for any help, gsatch (4 Replies)
Discussion started by: gsatch
4 Replies
Login or Register to Ask a Question