The problem is that sometimes the users don't log out at the end of the day. I'd like to put a routine in which will exit the menu and logout after 60 minutes of inactivity.
You need signals and alarms. Every time you read input, you set an alarm first.
Code:
sub read_input {
local $SIG{ALRM} = sub { die "session timed out" };
alarm 3600;
my $input = <STDIN>;
alarm 0;
return $input;
};
if <STDIN> returns first, the alarm is cancelled. If the alarm fires first, the program dies. If you want to do any clean-up, you could put it in an END block or use the more elaborate
Code:
sub read_input {
my $input;
eval {
local $SIG{ALRM} = sub { die 'session timed out' };
alarm 3600;
$input = <STDIN>;
alarm 0;
}
if ( $@ && $_ eq 'session timed out' ) {
# clean-up code here
exit;
}
return $input;
};
Yours,
f
"As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilkes
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.