2

開いているファイルハンドル、またはスクリプトを終了する前に修正する必要があるものがあるとします。また、長いループがあり、プロセスが署名を受け取った場合にループを中断したいと考えています。これを行う最もクリーンな方法は何ですか?

これが問題の実例です。

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")
4

1 に答える 1