Sponsored Content
Top Forums Shell Programming and Scripting Perl | catching the letter 'Q' for exit. Post 302420214 by RedGrinGo on Tuesday 11th of May 2010 03:37:45 AM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

Letter Frequency Decryption Program in Perl

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

6. 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

7. 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

8. 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

9. 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

10. 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
Net::Server::SIG(3)					User Contributed Perl Documentation				       Net::Server::SIG(3)

NAME
Net::Server::SIG - adpf - Safer signal handling SYNOPSIS
use Net::Server::SIG qw(register_sig check_sigs); use IO::Select (); use POSIX qw(WNOHANG); my $select = IO::Select->new(); register_sig(PIPE => 'IGNORE', HUP => 'DEFAULT', USR1 => sub { print "I got a SIG $_[0] "; }, USR2 => sub { print "I got a SIG $_[0] "; }, CHLD => sub { 1 while (waitpid(-1, WNOHANG) > 0); }, ); ### add some handles to the select $select->add(*STDIN); ### loop forever trying to stay alive while ( 1 ){ ### do a timeout to see if any signals got passed us ### while we were processing another signal my @fh = $select->can_read(10); my $key; my $val; ### this is the handler for safe (fine under unsafe also) if( &check_sigs() ){ # or my @sigs = &check_sigs(); next unless @fh; } my $handle = $fh[@fh]; ### do something with the handle } DESCRIPTION
Signals in Perl 5 are unsafe. Some future releases may be able to fix some of this (ie Perl 5.8 or 6.0), but it would be nice to have some safe, portable signal handling now. Clarification - much of the time, signals are safe enough. However, if the program employs forking or becomes a daemon which can receive many simultaneous signals, then the signal handling of Perl is normally not sufficient for the task. Using a property of the select() function, Net::Server::SIG attempts to fix the unsafe problem. If a process is blocking on select() any signal will short circuit the select. Using this concept, Net::Server::SIG does the least work possible (changing one bit from 0 to 1). And depends upon the actual processing of the signals to take place immediately after the the select call via the "check_sigs" function. See the example shown above and also see the sigtest.pl script located in the examples directory of this distribution. FUNCTIONS
"register_sig($SIG => &code_ref)" Takes key/value pairs where the key is the signal name, and the argument is either a code ref, or the words 'DEFAULT' or 'IGNORE'. The function register_sig must be used in conjuction with check_sigs, and with a blocking select() function call -- otherwise, you will observe the registered signal mysteriously vanish. "unregister_sig($SIG)" Takes the name of a signal as an argument. Calls register_sig with a this signal name and 'DEFAULT' as arguments (same as register_sig(SIG,'DEFAULT') "check_sigs()" Checks to see if any registered signals have occured. If so, it will play the registered code ref for that signal. Return value is array containing any SIGNAL names that had occured. AUTHORS
Paul Seamons (paul@seamons.com) Rob B Brown (rob@roobik.com) - Provided a sounding board and feedback in creating Net::Server::SIG and sigtest.pl. LICENSE
This package may be distributed under the terms of either the GNU General Public License or the Perl Artistic License All rights reserved. perl v5.12.1 2007-02-03 Net::Server::SIG(3)
All times are GMT -4. The time now is 09:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy