假设我有一个打开的文件句柄,或者在退出脚本之前我必须修复的任何东西。我也有一个很长的循环,如果进程收到一个信号,我想打破循环。最干净的方法是什么?
这是问题的说明;
use sigtrap 'handler' => \&sigint_handler, 'INT';
sub sigint_handler {
print("\nI see you are trying to escape this evil infinite loop,
but there is nothing that I can do to help you :(\n");
}
my $the_developper_is_unable_to_end_this_mess = 1;
open(my $handle, "< some.important.file");
while($the_developper_is_unable_to_end_this_mess) {
print("And the evil loop rolls again and again...\n");
sleep(3);
}
close($handle);
print("everything went better than expected\n")