Reputation: 6381
How can I catch a keyboard interrupt in Perl?
while(1) {
try {
print 1;
}
catch KeyboardInterrupt {
print 2;
}
}
Upvotes: 2
Views: 779
Reputation: 8542
You appear to be trying to write Python here.
"Keyboard interrupt", most likely means SIGINT
. You can handle signals using the %SIG
hash. For example:
$SIG{INT} = sub { print "Received SIGINT\n" };
Upvotes: 6