Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 Perl 中捕捉键盘中断?
while(1) { try { print 1; } catch KeyboardInterrupt { print 2; } }
您似乎正在尝试在这里编写 Python。
“键盘中断”,很可能是指SIGINT. %SIG您可以使用哈希处理信号。例如:
SIGINT
%SIG
$SIG{INT} = sub { print "Received SIGINT\n" };