Operating System - HP-UX
1755690 Members
2774 Online
108837 Solutions
New Discussion юеВ

captive perl menu - trap user keystrokes

 
SOLVED
Go to solution
Rick Garland
Honored Contributor

captive perl menu - trap user keystrokes

Hi all:

Got Perl 5.8.3 on HPUX 11x systems. I have made a type of menu program for the helpdesk personnel. Question, I want this menu to be captive (it is) but I also want to prevent users from breaking out of the menu.

What are the traps? How do I define them?

Many thanks!
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: captive perl menu - trap user keystrokes

Signal handlers (traps) in Perl are done almost exactly the way they are done in C.

#!/usr/bin/perl

my $Flag = 0; # we'll set this guy in a 'trap'

sub inttrap
{
$Flag = 1;
return(-1);
} # inttrap

$SIG{INT} = \&inttrap; # associate a signal with a subroutine

# Now for an extremely simple read statement.

my $s = ;

print "Flag = ${Flag}\n"

Examine the value displayed when you do and don't press the intr key.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: captive perl menu - trap user keystrokes

I should also mention (since this is probably what you want to do) that it's also very easy to ignore signals.

$SIG{INT} = 'IGNORE';
$SIG{HUP} = 'IGNORE';
If it ain't broke, I can fix that.
Rick Garland
Honored Contributor

Re: captive perl menu - trap user keystrokes

many thanks!