如何在Perl中捕获键盘中断?
while(1) {
try {
print 1;
}
catch KeyboardInterrupt {
print 2;
}
}
Run Code Online (Sandbox Code Playgroud)
你似乎试图在这里编写Python.
"键盘中断",很可能意味着SIGINT.您可以使用%SIG哈希处理信号.例如:
$SIG{INT} = sub { print "Received SIGINT\n" };
Run Code Online (Sandbox Code Playgroud)